Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 260 additions & 0 deletions .github/workflows/r06-w2-19-corrected-playertext.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
name: R06 W2-19 D2 corrected player text

on:
push:
branches:
- r06-w2-19-d2-hint-localization-0928-sol
pull_request:
paths:
- '.github/workflows/r06-w2-19-corrected-playertext.yml'
- 'docs/campaigns/PA/R06_W2_19_CORRECTED/**'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: r06-w2-19-d2-corrected-playertext
cancel-in-progress: false

jobs:
correct-and-prove:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Recover exact immutable D2 baseline
shell: bash
run: |
set -euo pipefail
source_commit="0e913d3cb001ec3f5dff3e6aa0a61069d05ed101"
source_path="release_inputs/dev2_w2_24/DEV_B_STAGE05_RECORD_SPLIT_STAGING.zip"
expected_zip="b681ea26d985eb754bde02a77254d40ab0920061edb9226fae7921a6740a06c0"
transport="$RUNNER_TEMP/d2-stage05.zip"
git fetch --no-tags origin "$source_commit"
git show "$source_commit:$source_path" > "$transport"
actual="$(sha256sum "$transport" | awk '{print $1}')"
test "$actual" = "$expected_zip"
unzip -t "$transport" >/dev/null
rm -rf "$RUNNER_TEMP/d2-stage05"
mkdir -p "$RUNNER_TEMP/d2-stage05"
unzip -q "$transport" -d "$RUNNER_TEMP/d2-stage05"
test -d "$RUNNER_TEMP/d2-stage05/D2_MATERIALIZATION/nodes"
echo "D2_W2_19_BASELINE_ZIP_PASS=$actual"

- name: Produce bounded corrected derivatives and proof
shell: bash
run: |
set -euo pipefail
python - "$RUNNER_TEMP/d2-stage05/D2_MATERIALIZATION" <<'PY'
import copy
import hashlib
import json
import pathlib
import sys

baseline_root = pathlib.Path(sys.argv[1])
output_root = pathlib.Path("docs/campaigns/PA/R06_W2_19_CORRECTED")
nodes_out = output_root / "nodes"
nodes_out.mkdir(parents=True, exist_ok=True)

parts = [f"part_{i:03d}.jsonl" for i in range(21, 27)]
mutable_top = {
"player_prompt", "success_feedback", "partial_feedback", "failure_feedback",
"rejection_reason", "functional_nonvisual_equivalent",
}
mutable_mapping = {"hints"}
mutable_list = {"rejected_answers"}
replacements = (
("локальному твердження", "локальному твердженню"),
("оцінювання обмежений", "оцінювання обмежене"),
("джерельна атрибуція for ", "джерельна атрибуція для "),
("identify мовця", "визначення мовця"),
("audience quoted by наратор Дій", "слухачі, процитовані оповідачем Дій"),
("an unnamed harmonized source voice", "невизначений гармонізований голос джерела"),
("source voice", "голос джерела"),
("свідчення/source", "свідчення/джерела"),
)
forbidden_after = tuple(old for old, _ in replacements)

def canonical(value):
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")

def sha(value):
return hashlib.sha256(value).hexdigest()

def protected(record):
return {
key: value for key, value in record.items()
if key not in mutable_top and key not in mutable_mapping and key not in mutable_list
}

def fix_text(text, counts):
result = text
for old, new in replacements:
n = result.count(old)
if n:
counts[old] = counts.get(old, 0) + n
result = result.replace(old, new)
return result

index = json.loads((baseline_root / "node_hash_index.json").read_text(encoding="utf-8"))
indexed = {}
for item in index.get("records", []):
if isinstance(item, dict) and isinstance(item.get("id"), str):
indexed[item["id"]] = item
if len(indexed) != 386:
raise SystemExit(f"W2_19_BASELINE_INDEX_COUNT_FAIL {len(indexed)}")

report_rows = []
occurrence_counts = {}
all_baseline = {}
all_candidate = {}
for part in parts:
src = baseline_root / "nodes" / part
if not src.is_file():
raise SystemExit(f"W2_19_BASELINE_PART_MISSING {part}")
corrected_lines = []
part_records = 0
for line_no, line in enumerate(src.read_text(encoding="utf-8").splitlines(), 1):
if not line.strip():
continue
baseline = json.loads(line)
if not isinstance(baseline, dict):
raise SystemExit(f"W2_19_NON_OBJECT {part}:{line_no}")
node_id = baseline.get("node_id")
if not isinstance(node_id, str) or not node_id or node_id in all_baseline:
raise SystemExit(f"W2_19_NODE_ID_FAIL {part}:{line_no}:{node_id}")
baseline_sha = sha(canonical(baseline))
indexed_item = indexed.get(node_id)
if not indexed_item or indexed_item.get("sha256") != baseline_sha:
raise SystemExit(f"W2_19_BASELINE_HASH_FAIL {node_id}")
indexed_part = str(indexed_item.get("part") or "")
if indexed_part and not indexed_part.endswith(part):
raise SystemExit(f"W2_19_BASELINE_PART_INDEX_FAIL {node_id}:{indexed_part}:{part}")

candidate = copy.deepcopy(baseline)
changed_paths = []
for field in sorted(mutable_top):
if field in candidate:
if not isinstance(candidate[field], str):
raise SystemExit(f"W2_19_MUTABLE_TYPE_FAIL {node_id}:{field}")
new = fix_text(candidate[field], occurrence_counts)
if new != candidate[field]:
candidate[field] = new
changed_paths.append(field)
for field in sorted(mutable_mapping):
value = candidate.get(field)
if not isinstance(value, dict) or not all(isinstance(v, str) for v in value.values()):
raise SystemExit(f"W2_19_MUTABLE_MAPPING_FAIL {node_id}:{field}")
for key in sorted(value):
new = fix_text(value[key], occurrence_counts)
if new != value[key]:
value[key] = new
changed_paths.append(f"{field}.{key}")
for field in sorted(mutable_list):
value = candidate.get(field)
if not isinstance(value, list) or not all(isinstance(v, str) for v in value):
raise SystemExit(f"W2_19_MUTABLE_LIST_FAIL {node_id}:{field}")
for i, old_value in enumerate(list(value)):
new = fix_text(old_value, occurrence_counts)
if new != old_value:
value[i] = new
changed_paths.append(f"{field}[{i}]")

if protected(baseline) != protected(candidate):
raise SystemExit(f"W2_19_PROTECTED_PROJECTION_FAIL {node_id}")
protected_sha = sha(canonical(protected(baseline)))
candidate_text = "\n".join(
[candidate.get(field, "") for field in sorted(mutable_top) if isinstance(candidate.get(field), str)]
+ [v for field in sorted(mutable_mapping) for v in candidate.get(field, {}).values()]
+ [v for field in sorted(mutable_list) for v in candidate.get(field, [])]
)
leaked = [pattern for pattern in forbidden_after if pattern in candidate_text]
if leaked:
raise SystemExit(f"W2_19_ARTIFACT_REMAINS {node_id}:{leaked}")
if not changed_paths:
raise SystemExit(f"W2_19_EXPECTED_PLAYER_TEXT_CHANGE_MISSING {node_id}")

corrected_sha = sha(canonical(candidate))
corrected_lines.append(canonical(candidate).decode("utf-8"))
report_rows.append({
"node_id": node_id,
"source_part": f"nodes/{part}",
"changed_player_paths": changed_paths,
"baseline_record_sha256": baseline_sha,
"corrected_record_sha256": corrected_sha,
"protected_projection_sha256": protected_sha,
})
all_baseline[node_id] = baseline_sha
all_candidate[node_id] = corrected_sha
part_records += 1
if part_records == 0:
raise SystemExit(f"W2_19_EMPTY_PART {part}")
(nodes_out / part).write_text("\n".join(corrected_lines) + "\n", encoding="utf-8")

count = len(report_rows)
if occurrence_counts.get("локальному твердження", 0) < count:
raise SystemExit("W2_19_SYSTEMIC_LOCAL_CLAIM_BASELINE_COUNT_FAIL")
if occurrence_counts.get("оцінювання обмежений", 0) < count:
raise SystemExit("W2_19_SYSTEMIC_GRADING_BASELINE_COUNT_FAIL")

def aggregate(mapping):
payload = "".join(f"{node_id}\t{mapping[node_id]}\n" for node_id in sorted(mapping)).encode("utf-8")
return sha(payload)

report = {
"schema": "R06_D2_W2_19_PLAYER_TEXT_CORRECTION_v1",
"status": "PASS",
"source": {
"staging_zip_sha256": "b681ea26d985eb754bde02a77254d40ab0920061edb9226fae7921a6740a06c0",
"parts": [f"nodes/{p}" for p in parts],
},
"scope": {
"node_count": count,
"mutable_top_level_text_fields": sorted(mutable_top),
"mutable_mapping_text_fields": sorted(mutable_mapping),
"mutable_list_text_fields": sorted(mutable_list),
"all_other_fields": "IMMUTABLE_FAIL_CLOSED",
},
"artifact_replacements": [
{"from": old, "to": new, "occurrences": occurrence_counts.get(old, 0)}
for old, new in replacements
],
"selected_baseline_aggregate_sha256": aggregate(all_baseline),
"selected_corrected_aggregate_sha256": aggregate(all_candidate),
"changes": sorted(report_rows, key=lambda row: row["node_id"]),
"independent_audit": "PENDING",
"source_truth_changed": False,
}
output_root.mkdir(parents=True, exist_ok=True)
(output_root / "W2_19_CORRECTION_REPORT.json").write_text(
json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8"
)
print(
"W2_19_CORRECTION_PASS",
f"nodes={count}",
f"baseline={report['selected_baseline_aggregate_sha256']}",
f"corrected={report['selected_corrected_aggregate_sha256']}",
)
PY

- name: Verify corrected derivatives match committed authority
shell: bash
run: |
set -euo pipefail
root="docs/campaigns/PA/R06_W2_19_CORRECTED"
test -f "$root/W2_19_CORRECTION_REPORT.json"
test -f "$root/nodes/part_021.jsonl"
test -f "$root/nodes/part_022.jsonl"
test -f "$root/nodes/part_023.jsonl"
test -f "$root/nodes/part_024.jsonl"
test -f "$root/nodes/part_025.jsonl"
test -f "$root/nodes/part_026.jsonl"
git diff --check
git diff --exit-code -- "$root"
test -z "$(git status --porcelain=v1 --untracked-files=all -- "$root")"
echo "W2_19_COMMITTED_AUTHORITY_MATCH_PASS"
Loading
Loading