agent-bios 0.19.4 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPENDENCIES.md +20 -5
- package/README.md +14 -19
- package/claude/agents/frontier.md +1 -1
- package/claude/guides/claude-prompting.md +475 -234
- package/claude/guides/cli-multi-model-workflow.md +8 -7
- package/claude/guides/gpt-prompting.md +319 -144
- package/claude/guides/session-distill-workflow.md +93 -43
- package/claude/guides/tooling-gotchas.md +3 -1
- package/codex/agents/frontier.toml +1 -1
- package/codex/agents/reviewer.toml +1 -1
- package/codex/agents/workhorse.toml +1 -1
- package/codex/guides/claude-prompting.md +475 -234
- package/codex/guides/cli-multi-model-workflow.md +8 -7
- package/codex/guides/gpt-prompting.md +319 -144
- package/codex/guides/session-distill-workflow.md +93 -43
- package/codex/guides/tooling-gotchas.md +3 -1
- package/compose/assemble.py +4 -1
- package/compose/canary.sh +8 -6
- package/compose/host_platform.py +158 -15
- package/compose/instructions-state.py +183 -41
- package/compose/instructions_install.py +222 -27
- package/compose/instructions_session.py +250 -75
- package/compose/instructions_setup_cli.py +2 -36
- package/compose/instructions_store.py +160 -3
- package/compose/instructions_transaction.py +29 -5
- package/docs/advanced-launch.md +5 -1
- package/docs/releases/0.20.0.md +102 -0
- package/docs/releases/0.20.1.md +76 -0
- package/install.sh +42 -14
- package/launch/agent-launch.py +152 -18
- package/launch/agent-launch.toml +28 -16
- package/launch/agent-launch.zsh +104 -13
- package/launch/claude_subcommands.py +179 -0
- package/launch/shell_integration.py +7 -1
- package/learn/collect-learning.py +60 -9
- package/learn/migrate-learnings.py +70 -4
- package/learn/redact.py +2 -1
- package/package.json +36 -3
- package/provenance.json +1 -1
- package/session-cost.py +80 -9
- package/session-distill/coverage.json +6 -0
- package/session-distill/distill.py +2575 -0
- package/session-distill/grammar/__init__.py +0 -0
- package/session-distill/grammar/owner_lines.py +874 -0
- package/session-distill/originators.json +9 -0
- package/session-distill/packets/cross_review.md +31 -0
- package/session-distill/packets/form.md +86 -0
- package/session-distill/packets/judge.md +81 -0
- package/session-distill/packets/placement_contract.md +90 -0
- package/session-distill/packets/propose.md +124 -0
- package/session-distill/packets/read.md +57 -0
- package/session-distill/packets/reconsider.md +53 -0
- package/session-distill/packets/s7b.md +65 -0
- package/session-distill/packets/s9b.md +39 -0
- package/session-distill/packets/stitch.md +35 -0
- package/session-distill/packets/sweep.md +33 -0
- package/session-distill/runlib/__init__.py +0 -0
- package/session-distill/runlib/bound.py +1102 -0
- package/session-distill/runlib/breaker.py +467 -0
- package/session-distill/runlib/census.py +2347 -0
- package/session-distill/runlib/claims.py +420 -0
- package/session-distill/runlib/controls.py +902 -0
- package/session-distill/runlib/coverage.py +881 -0
- package/session-distill/runlib/declare.py +888 -0
- package/session-distill/runlib/delivery_evidence.py +1145 -0
- package/session-distill/runlib/derive.py +812 -0
- package/session-distill/runlib/destinations.py +3072 -0
- package/session-distill/runlib/dispatch.py +7940 -0
- package/session-distill/runlib/drift.py +1077 -0
- package/session-distill/runlib/entry.py +401 -0
- package/session-distill/runlib/evidence.py +890 -0
- package/session-distill/runlib/exposure.py +1162 -0
- package/session-distill/runlib/gate.py +2727 -0
- package/session-distill/runlib/gitread.py +79 -0
- package/session-distill/runlib/inventory.py +19624 -0
- package/session-distill/runlib/journal.py +1919 -0
- package/session-distill/runlib/ledger.py +3210 -0
- package/session-distill/runlib/ledger_compat.py +101 -0
- package/session-distill/runlib/ledger_migration.py +190 -0
- package/session-distill/runlib/lifecycle_intake.py +693 -0
- package/session-distill/runlib/lineage.py +454 -0
- package/session-distill/runlib/measures.py +249 -0
- package/session-distill/runlib/monitor.py +1180 -0
- package/session-distill/runlib/operations.py +522 -0
- package/session-distill/runlib/packet.py +838 -0
- package/session-distill/runlib/placement.py +1769 -0
- package/session-distill/runlib/projection.py +4090 -0
- package/session-distill/runlib/ranking.py +740 -0
- package/session-distill/runlib/receipts.py +200 -0
- package/session-distill/runlib/records.py +1965 -0
- package/session-distill/runlib/search.py +249 -0
- package/session-distill/runlib/sequencing.py +829 -0
- package/session-distill/runlib/sources.py +641 -0
- package/session-distill/runlib/stage_adjudicate.py +845 -0
- package/session-distill/runlib/stage_apply.py +1378 -0
- package/session-distill/runlib/stage_approvals.py +758 -0
- package/session-distill/runlib/stage_close.py +1220 -0
- package/session-distill/runlib/stage_confirm.py +929 -0
- package/session-distill/runlib/stage_delivery.py +3080 -0
- package/session-distill/runlib/stage_form.py +2576 -0
- package/session-distill/runlib/stage_judge.py +4248 -0
- package/session-distill/runlib/stage_propose.py +3307 -0
- package/session-distill/runlib/stage_read.py +5179 -0
- package/session-distill/runlib/stage_render.py +2739 -0
- package/session-distill/runlib/stage_retrieve.py +924 -0
- package/session-distill/runlib/stage_review_korean.py +1002 -0
- package/session-distill/runlib/stage_review_proposals.py +1292 -0
- package/session-distill/runlib/stagelock.py +412 -0
- package/session-distill/runlib/stop.py +1061 -0
- package/session-distill/runlib/targets.py +809 -0
- package/session-distill/runlib/usage.py +280 -0
- package/session-distill/runlib/validate.py +319 -0
- package/session-distill/runlib/views.py +4327 -0
- package/session-distill/schemas/adjudication.schema.json +35 -0
- package/session-distill/schemas/approval.schema.json +35 -0
- package/session-distill/schemas/census.schema.json +128 -0
- package/session-distill/schemas/checks.schema.json +207 -0
- package/session-distill/schemas/claim.schema.json +16 -0
- package/session-distill/schemas/confirmation.schema.json +24 -0
- package/session-distill/schemas/coverage.schema.json +66 -0
- package/session-distill/schemas/cross_review.schema.json +24 -0
- package/session-distill/schemas/event.schema.json +20 -0
- package/session-distill/schemas/evidence.schema.json +20 -0
- package/session-distill/schemas/expected_observation.schema.json +18 -0
- package/session-distill/schemas/form.schema.json +103 -0
- package/session-distill/schemas/intake.schema.json +71 -0
- package/session-distill/schemas/inventory.schema.json +872 -0
- package/session-distill/schemas/judge.schema.json +77 -0
- package/session-distill/schemas/ledger.schema.json +313 -0
- package/session-distill/schemas/observation.schema.json +16 -0
- package/session-distill/schemas/propose.schema.json +555 -0
- package/session-distill/schemas/read.schema.json +76 -0
- package/session-distill/schemas/reconsider.schema.json +122 -0
- package/session-distill/schemas/run.schema.json +150 -0
- package/session-distill/schemas/s7b.schema.json +200 -0
- package/session-distill/schemas/s9b.schema.json +28 -0
- package/session-distill/schemas/stitch.schema.json +25 -0
- package/session-distill/schemas/sweep.schema.json +25 -0
- package/session-distill/seats.json +149 -0
- package/session-distill/tables/allowed_pairs.json +257 -0
- package/session-distill/tables/controls.json +30 -0
- package/session-distill/tables/delivery_evidence.json +36 -0
- package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
- package/session-distill/tables/destinations.json +684 -0
- package/session-distill/tables/drift_layers.json +68 -0
- package/session-distill/tables/exposure_rules.json +192 -0
- package/session-distill/tables/placement_rules.json +148 -0
- package/session-distill/tables/propose_fixtures.json +154 -0
- package/session-distill/tables/ranking.json +194 -0
- package/session-distill/tables/redundancy.json +10 -0
- package/session-distill/tables/structural_rules.json +44 -0
- package/session-distill/tables/transition_fixtures.json +398 -0
- package/session-distill/tables/transitions.json +69 -0
- package/session-distill/tables/unit_outcome.json +67 -0
- package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
- package/wrappers/claude-run.sh +481 -33
- package/wrappers/claude_hermetic_evidence.py +1423 -0
- package/wrappers/codex-helm.sh +46 -15
- package/wrappers/codex-run.sh +183 -20
- package/wrappers/codex_frame_filter.py +1199 -0
- package/wrappers/codex_protocol.py +737 -0
- package/wrappers/jsonl_lines.py +65 -0
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""S10b confirm (plan WP-20 K6; design §10.3, §10.4; release-1 amendment: one pass, no S8, no confirmation episodes).
|
|
3
|
+
|
|
4
|
+
`승인` approves an item on condition that the owner confirms the exact final set it lands in. This stage builds that
|
|
5
|
+
set from what S10 committed, shows it to the owner once, and binds the owner's `확인: 확정` to it. It has two parts.
|
|
6
|
+
|
|
7
|
+
**build** reads S9's current rows (`review.v<n>.json`), S10's approvals and committed parses, S7b's review and S2's
|
|
8
|
+
current inventory, and writes confirmation version k: `confirm/v<k>/manifest.json`, the page the owner reads
|
|
9
|
+
(`confirm.ko.v<k>.md`) and the owner's copy of it (`confirm-decision.ko.v<k>.md`, where `확인:` is written). Each item
|
|
10
|
+
whose last approval row decides it lands in exactly one place:
|
|
11
|
+
|
|
12
|
+
- **F**: an approved item that changes the library, at the item_sha the current rows carry and not awaiting R
|
|
13
|
+
(`stage_approvals.f_of`, the function S10 hashed). `configuration_sha` is S10's
|
|
14
|
+
(`stage_approvals.configuration_sha`, over the declaration's `config_manifest_B` and F).
|
|
15
|
+
- **ledger_only**: an approved proposal whose disposition changes no installed instruction (design §10.4: keep,
|
|
16
|
+
incubate, drop, none), each member of an approved legacy group under its group, and an adopted S7b alternative
|
|
17
|
+
whose disposition is ledger-only. They are not part of F; S12 applies them to the ledger.
|
|
18
|
+
- **apart, by name**: an approval the current rows made stale (decided again in a new review version); an approved
|
|
19
|
+
item awaiting R (release 1 applies none); a 수정, and an adopted alternative that would change the library, which
|
|
20
|
+
have no operations of their own and go back to S7 (`needs_proposal`); and an approval of a row that carries no
|
|
21
|
+
proposal (`nothing_to_apply`: a returned, rejected, disputed or quarantined row).
|
|
22
|
+
|
|
23
|
+
An adopted alternative is held to S7b's recorded review: one S7b no longer offers in the same form is
|
|
24
|
+
ALTERNATIVE_STALE, and nothing is built. The latest committed parse must have bound the configuration this build
|
|
25
|
+
computes; one that bound another is CONFIRMATION_UNBOUND configuration_sha, and nothing is built. F's exact order is
|
|
26
|
+
answered again over the approved subset alone (`sequencing.subset_answer`, from the current library's paths, each
|
|
27
|
+
operation as S7 proposed it): a subset with no valid order is shown to the owner with its refusal, and that version
|
|
28
|
+
carries no confirmation block. S8 is deferred, so the confirmation's cases and results are the named state
|
|
29
|
+
`untested: s8_deferred`, never null.
|
|
30
|
+
|
|
31
|
+
**confirm** reads the owner's copy of the latest version (`grammar/owner_lines.py`; the block is bound to the
|
|
32
|
+
manifest's set hash, CONFIRM_STALE otherwise), builds the final set again from the same inputs, and holds the
|
|
33
|
+
manifest to it by field: a moved `item_sha`, a moved `configuration_sha`, manifest bytes that are not the ones build
|
|
34
|
+
recorded, and results that are no longer the deferred state are each CONFIRMATION_UNBOUND, by field. The shared
|
|
35
|
+
record checks refuse first when an input moved after build (INPUT_STALE, INPUT_INVALID). `확인: 확정` writes
|
|
36
|
+
`confirmation.json`: the bound approval ids, F's `configuration_sha`, the manifest's sha256 and the results state,
|
|
37
|
+
which is design §10.3's record and what S11 applies. `확인: 반려` with its 메모 is not a confirmation: it writes
|
|
38
|
+
`confirm/v<k>/returned.json`, and the owner decides again in a new review version. A version is decided once, an
|
|
39
|
+
older version than the latest is not decided at all, and a run whose final set is confirmed builds no new version.
|
|
40
|
+
|
|
41
|
+
stage_confirm.py --self-test
|
|
42
|
+
"""
|
|
43
|
+
import json
|
|
44
|
+
import pathlib
|
|
45
|
+
import re
|
|
46
|
+
import sys
|
|
47
|
+
|
|
48
|
+
if __package__ in (None, ""): # run as a script: put session-distill/ on the import path
|
|
49
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
50
|
+
from grammar import owner_lines # noqa: E402
|
|
51
|
+
from runlib import (placement, records, sequencing, stage_adjudicate, stage_approvals, # noqa: E402
|
|
52
|
+
stage_review_proposals, validate)
|
|
53
|
+
from runlib.records import Refused # noqa: E402
|
|
54
|
+
|
|
55
|
+
HERE = pathlib.Path(__file__).resolve().parents[1]
|
|
56
|
+
STAGE, BUILD, CONFIRM = "S10b", "build", "confirm"
|
|
57
|
+
CONFIRMATION = "confirmation.json"
|
|
58
|
+
INVENTORY = "inventory/current.json"
|
|
59
|
+
S8_DEFERRED = stage_approvals.S8_DEFERRED
|
|
60
|
+
LEDGER_ONLY = ("keep", "incubate", "drop", "none") # design §10.4
|
|
61
|
+
# design §10.3: "a confirmation record binding the approval ids to F's configuration_sha and the confirmation
|
|
62
|
+
# manifest and results hashes" - copied once and held to the schema's required set by the self-test (done-when 9)
|
|
63
|
+
DESIGN_10_3_CONFIRMATION = ("approval_ids", "configuration_sha", "manifest_sha", "results_sha")
|
|
64
|
+
PLAN_CONFIRMATION_ADDS = ("confirmation_id", "confirm_version", "decision_input_sha", "at")
|
|
65
|
+
SCHEMA_PATH = HERE / "schemas" / "confirmation.schema.json"
|
|
66
|
+
_VALIDATOR = []
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def manifest_rel(version):
|
|
70
|
+
return f"confirm/v{version}/manifest.json"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def render_name(version):
|
|
74
|
+
return f"confirm.ko.v{version}.md"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def copy_name(version):
|
|
78
|
+
return f"confirm-decision.ko.v{version}.md"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def returned_rel(version):
|
|
82
|
+
return f"confirm/v{version}/returned.json"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def inputs_of(run_dir):
|
|
86
|
+
"""What both parts read, every one through the shared record checks: S10's adjudicated versions among them, since
|
|
87
|
+
S9 rendered S7b's review with their second-pass reviews laid over it and an adopted alternative is held to that."""
|
|
88
|
+
return ([{"artifact": f"review.v{stage_approvals.latest_version(run_dir)}.json", "producer_stage": "S9"},
|
|
89
|
+
{"artifact": stage_approvals.APPROVALS, "producer_stage": "S10"},
|
|
90
|
+
{"artifact": stage_review_proposals.OUTPUT, "producer_stage": "S7b"},
|
|
91
|
+
{"artifact": INVENTORY, "producer_stage": "S2"}]
|
|
92
|
+
+ [{"artifact": f"parsed.v{p['version']}.json", "producer_stage": "S10"}
|
|
93
|
+
for p in stage_approvals.parsed_in(run_dir)]
|
|
94
|
+
+ list(stage_adjudicate.adjudicated_inputs(run_dir)))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def target_of(item, candidates):
|
|
98
|
+
"""`(kind, entry id | None, resolves | None)`: `entry` for an item decided on an existing ledger
|
|
99
|
+
entry (a legacy entry, a due decision), `new` for a candidate with no entry. S12 records by it, and S10b's page
|
|
100
|
+
says by it where an item without a file change is kept."""
|
|
101
|
+
cid = item["item_id"]
|
|
102
|
+
cand = candidates.get(cid) or {}
|
|
103
|
+
lifecycle = cand.get("lifecycle") or {}
|
|
104
|
+
source = cand.get("source") or (cid.split(":", 1)[0] if ":" in cid else "formed")
|
|
105
|
+
if source == "legacy":
|
|
106
|
+
return "entry", lifecycle.get("target_entry") or cid.split(":", 1)[1], None
|
|
107
|
+
if source == "due_decision":
|
|
108
|
+
return "entry", lifecycle.get("target_entry") or cid.split(":", 1)[1].split("@", 1)[0], lifecycle.get("resolves")
|
|
109
|
+
return "new", None, None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def kept_in_run_only(item):
|
|
113
|
+
"""An item S12 gives no ledger row: a `none` on a candidate with no entry stays in the run's close record alone
|
|
114
|
+
(F-40)."""
|
|
115
|
+
return item.get("disposition") == "none" and target_of(item, {})[0] == "new"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _without_reason(alternative):
|
|
119
|
+
return {k: v for k, v in alternative.items() if k != "reason"} if isinstance(alternative, dict) else None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# ---- the final set ----------------------------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
def adopted_gap(disposition, reason):
|
|
125
|
+
"""Why an adopted S7b alternative cannot be closed as it stands, or None. S12 records an incubate's observation and
|
|
126
|
+
expiry, a keep's record over the units it keeps, and a drop's reason (`stage_close.element_of`), and S7b's
|
|
127
|
+
alternative carries a reason alone: only a `none` and a `drop` with its reason close as adopted (release 1's
|
|
128
|
+
confirmation review, both rounds)."""
|
|
129
|
+
if disposition == "incubate":
|
|
130
|
+
return "adopted_incubate_without_observation"
|
|
131
|
+
if disposition == "keep":
|
|
132
|
+
return "adopted_keep_without_units"
|
|
133
|
+
if disposition == "drop" and not reason:
|
|
134
|
+
return "adopted_without_reason"
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def final_set(declaration, current, approvals, s7b, parses, library):
|
|
139
|
+
"""`(manifest, problems)`: the final set S10's approvals leave over the current rows. Pure, every input given:
|
|
140
|
+
`current` the current rows document (with `_sha256`, its file's hash), `approvals` approvals.jsonl's rows in
|
|
141
|
+
order, `s7b` S7b's review document, `parses` the committed parses in order, `library` the paths the current
|
|
142
|
+
inventory holds."""
|
|
143
|
+
problems = []
|
|
144
|
+
last = {}
|
|
145
|
+
for a in approvals:
|
|
146
|
+
last[a["item_id"]] = a
|
|
147
|
+
rows = {r["item_id"]: r for r in current["rows"]}
|
|
148
|
+
order = [r["item_id"] for r in current["rows"]]
|
|
149
|
+
order += [m for r in current["rows"] for m in r.get("members") or []]
|
|
150
|
+
offered = {r.get("item_id"): _without_reason(r.get("alternative")) for r in (s7b or {}).get("reviews") or []}
|
|
151
|
+
f = stage_approvals.f_of(current, approvals)
|
|
152
|
+
config = stage_approvals.configuration_sha(declaration, f)
|
|
153
|
+
in_f = {item["item_id"] for item in f}
|
|
154
|
+
ledger_only, awaiting, stale, needs_proposal, nothing, bound = [], [], [], [], [], []
|
|
155
|
+
for item_id in order:
|
|
156
|
+
a = last.get(item_id)
|
|
157
|
+
if a is None:
|
|
158
|
+
continue
|
|
159
|
+
row = rows.get(a.get("member_of") or item_id)
|
|
160
|
+
if row is None or a["item_sha"] != row["item_sha"]:
|
|
161
|
+
stale.append({"item_id": item_id, "approval_id": a["approval_id"]})
|
|
162
|
+
continue
|
|
163
|
+
proposal = row.get("proposal") if row.get("status") == "proposed" else None
|
|
164
|
+
if a["decision"] == "approve":
|
|
165
|
+
if item_id in in_f:
|
|
166
|
+
bound.append(a["approval_id"])
|
|
167
|
+
elif a.get("member_of"):
|
|
168
|
+
ledger_only.append({"item_id": item_id, "approval_id": a["approval_id"], "member_of": a["member_of"],
|
|
169
|
+
"disposition": row.get("disposition") or "none",
|
|
170
|
+
"legacy_word": row.get("legacy_word")})
|
|
171
|
+
bound.append(a["approval_id"])
|
|
172
|
+
elif proposal and row.get("awaiting_R"):
|
|
173
|
+
awaiting.append({"item_id": item_id, "approval_id": a["approval_id"],
|
|
174
|
+
"reason": row.get("awaiting_R_reason")})
|
|
175
|
+
elif proposal and not row.get("changes_library"):
|
|
176
|
+
ledger_only.append({"item_id": item_id, "approval_id": a["approval_id"],
|
|
177
|
+
"disposition": proposal.get("disposition") or row.get("disposition") or "none"})
|
|
178
|
+
bound.append(a["approval_id"])
|
|
179
|
+
else:
|
|
180
|
+
nothing.append({"item_id": item_id, "approval_id": a["approval_id"], "status": row.get("status")})
|
|
181
|
+
elif a["decision"] == "revise" and a.get("alternative"):
|
|
182
|
+
shown = _without_reason((row.get("s7b") or {}).get("alternative"))
|
|
183
|
+
held = offered.get(item_id)
|
|
184
|
+
if not shown or shown != held:
|
|
185
|
+
problems.append(f"ALTERNATIVE_STALE {item_id}: the owner adopted S7b's alternative "
|
|
186
|
+
f"{(shown or {}).get('disposition')!r}, and S7b's recorded review now offers "
|
|
187
|
+
f"{(held or {}).get('disposition')!r}; decide it again in a new review version")
|
|
188
|
+
elif shown.get("disposition") in LEDGER_ONLY:
|
|
189
|
+
# what S12 needs of it is decided now, before the owner confirms (Codex release-1 review F2): an
|
|
190
|
+
# alternative carries a reason and no observation, so an incubate, or a keep or drop without its
|
|
191
|
+
# reason, is S7's to propose again, and the reason the owner read travels to the close
|
|
192
|
+
reason = ((row.get("s7b") or {}).get("alternative") or {}).get("reason")
|
|
193
|
+
reason = reason if isinstance(reason, str) and reason.strip() else None
|
|
194
|
+
gap = adopted_gap(shown["disposition"], reason)
|
|
195
|
+
if gap:
|
|
196
|
+
needs_proposal.append({"item_id": item_id, "approval_id": a["approval_id"],
|
|
197
|
+
"disposition": shown["disposition"], "why": gap})
|
|
198
|
+
else:
|
|
199
|
+
ledger_only.append({"item_id": item_id, "approval_id": a["approval_id"],
|
|
200
|
+
"disposition": shown["disposition"], "adopted": a["alternative"],
|
|
201
|
+
"alternative_reason": reason})
|
|
202
|
+
bound.append(a["approval_id"])
|
|
203
|
+
else:
|
|
204
|
+
needs_proposal.append({"item_id": item_id, "approval_id": a["approval_id"],
|
|
205
|
+
"disposition": shown.get("disposition"), "why": "adopted_alternative"})
|
|
206
|
+
elif a["decision"] == "revise":
|
|
207
|
+
needs_proposal.append({"item_id": item_id, "approval_id": a["approval_id"],
|
|
208
|
+
"disposition": row.get("disposition"), "why": "revise_note"})
|
|
209
|
+
latest = parses[-1] if parses else {}
|
|
210
|
+
if latest.get("configuration_sha") != config:
|
|
211
|
+
problems.append(f"CONFIRMATION_UNBOUND configuration_sha: the last parse (v{latest.get('version')}) bound "
|
|
212
|
+
f"{str(latest.get('configuration_sha'))[:12]}, and the final set's F is {config[:12]} now; "
|
|
213
|
+
"parse the current review version first")
|
|
214
|
+
steps = [{"item_id": i["item_id"], "operations": list((rows[i["item_id"]].get("proposal") or {})
|
|
215
|
+
.get("operations") or [])} for i in f]
|
|
216
|
+
answer = (sequencing.subset_answer(steps, base={path: "present" for path in library}) if steps
|
|
217
|
+
else {"set_hash": None, "sequenced": None, "order": [], "reason": "F is empty: nothing to order"})
|
|
218
|
+
shas = {i: rows[i]["item_sha"] for i in in_f}
|
|
219
|
+
shas.update({x["item_id"]: rows[x.get("member_of") or x["item_id"]]["item_sha"] for x in ledger_only})
|
|
220
|
+
manifest = {"stage": STAGE, "review_version": current["version"], "review_rows_sha256": current.get("_sha256"),
|
|
221
|
+
"configuration_sha": config, "config_manifest_B": (declaration or {}).get("config_manifest_B"),
|
|
222
|
+
"F": f, "ledger_only": ledger_only, "awaiting_R": awaiting, "stale": stale,
|
|
223
|
+
"needs_proposal": needs_proposal, "nothing_to_apply": nothing, "approval_ids": sorted(bound),
|
|
224
|
+
"item_shas": dict(sorted(shas.items())), "sequencing": answer,
|
|
225
|
+
"cases": S8_DEFERRED, "results": S8_DEFERRED,
|
|
226
|
+
"confirmable": bool(bound) and answer.get("sequenced") is not False}
|
|
227
|
+
# Release 1 changes no library file: an approved change cannot be confirmed, whatever approved it, so the owner
|
|
228
|
+
# is told before confirming rather than S11 refusing after (S7 and S7b refuse such an answer upstream)
|
|
229
|
+
if placement.release_scope() == "release_1":
|
|
230
|
+
problems += [f"RELEASE_1_NO_LIBRARY_CHANGE S10b {item['item_id']}: approved as a change to a library file, "
|
|
231
|
+
f"and release 1 changes none; decide it again in a new review version" for item in f]
|
|
232
|
+
return manifest, problems
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def set_sha(manifest):
|
|
236
|
+
return stage_approvals.sha256_of(manifest)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
# ---- the owner's page -------------------------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
def page(manifest, version):
|
|
242
|
+
"""The page the owner reads: the final set in the review's rank order, what is apart from it and why, the order,
|
|
243
|
+
the deferred tests, and the one block for `확인:` when the set can be confirmed."""
|
|
244
|
+
release_1 = placement.release_scope() == "release_1"
|
|
245
|
+
out = [f"# 최종 확인 v{version}", "",
|
|
246
|
+
f"검토 v{manifest['review_version']}에서 승인한 항목으로 만든 최종 집합입니다."
|
|
247
|
+
+ ("" if release_1 else " 확정하면 S11이 이 집합을 아래 순서대로 적용합니다."), "",
|
|
248
|
+
owner_lines.RELEASE_1_CONFIRM_EFFECT if release_1 else owner_lines.CONFIRM_EFFECT, "",
|
|
249
|
+
f"- 구성 해시: {manifest['configuration_sha'][:16]}", f"- 시험: {S8_DEFERRED} (S8은 다음 릴리스에 들어옵니다)", "",
|
|
250
|
+
"## 라이브러리를 바꾸는 항목 (F)", ""]
|
|
251
|
+
out += [f"- {i['item_id']}: " + ", ".join(f"{op.get('type')} {op.get('target')}" for op in i["operations"])
|
|
252
|
+
for i in manifest["F"]] or ["- 없음"]
|
|
253
|
+
out += ["", "## 파일을 바꾸지 않는 항목", "",
|
|
254
|
+
"아래 항목은 S11이 파일을 바꾸지 않습니다. S12가 대장에 결정을 남기고, 대장에 항목이 없는 새 후보의 "
|
|
255
|
+
"`none`(바꾸지 않음)은 대장에 줄을 만들지 않고 이번 실행의 마무리 기록(close.json)에만 남습니다.", ""]
|
|
256
|
+
out += [f"- {i['item_id']}: {i['disposition']}" + (f" (묶음 {i['member_of']})" if i.get("member_of") else "")
|
|
257
|
+
+ (" (S7b 대안 채택)" if i.get("adopted") else "")
|
|
258
|
+
+ (" — 이번 실행 기록에만 남음" if kept_in_run_only(i) else " — 대장에 기록")
|
|
259
|
+
for i in manifest["ledger_only"]] or ["- 없음"]
|
|
260
|
+
out += ["", "## 이번 확정에 들어가지 않는 승인", ""]
|
|
261
|
+
why = {"adopted_alternative": "채택한 S7b 대안이 라이브러리를 바꾸므로 S7이 작업을 제안해야 합니다",
|
|
262
|
+
"adopted_incubate_without_observation": "채택한 S7b 대안 incubate에는 관찰 계획과 만료가 없어, S7이 그것을 "
|
|
263
|
+
"갖춘 제안을 다시 만들어야 합니다",
|
|
264
|
+
"adopted_keep_without_units": "채택한 S7b 대안 keep에는 지킬 단위가 없어, S7이 그것을 갖춘 제안을 다시 "
|
|
265
|
+
"만들어야 합니다",
|
|
266
|
+
"adopted_without_reason": "채택한 S7b 대안에 이유가 없어, S7이 이유를 갖춘 제안을 다시 만들어야 합니다",
|
|
267
|
+
"revise_note": "수정 메모와 함께 S7로 돌아갑니다"}
|
|
268
|
+
apart = [f"- {i['item_id']}: R을 기다립니다 ({i.get('reason') or '이유 없음'})" for i in manifest["awaiting_R"]]
|
|
269
|
+
apart += [f"- {i['item_id']}: 승인한 뒤 행이 바뀌어 새 검토 판에서 다시 결정합니다" for i in manifest["stale"]]
|
|
270
|
+
apart += [f"- {i['item_id']}: {why.get(i['why'], i['why'])}" for i in manifest["needs_proposal"]]
|
|
271
|
+
apart += [f"- {i['item_id']}: 적용할 제안이 없는 행입니다 (상태 {i.get('status')})" for i in manifest["nothing_to_apply"]]
|
|
272
|
+
out += apart or ["- 없음"]
|
|
273
|
+
answer = manifest["sequencing"]
|
|
274
|
+
out += ["", "## 적용 순서", ""]
|
|
275
|
+
if answer.get("sequenced") is False:
|
|
276
|
+
out += [f"- 승인한 부분집합에는 유효한 순서가 없습니다 ({answer.get('refusal')}).",
|
|
277
|
+
"- 이 판은 확정할 수 없습니다. 새 검토 판에서 항목을 다시 결정하세요."]
|
|
278
|
+
else:
|
|
279
|
+
out += [f"{n}. {i}" for n, i in enumerate(answer.get("order") or [], 1)] or ["- F가 비어 있어 순서가 없습니다."]
|
|
280
|
+
out += [""]
|
|
281
|
+
# every line the text will hold, not every string it was made from: a value carrying a line break is two lines
|
|
282
|
+
found = [f"OWNER_SHAPED_TEXT line {n}: {line[:40]!r}" for n, line in enumerate("\n".join(out).split("\n"), 1)
|
|
283
|
+
if owner_lines.owner_shaped(line)]
|
|
284
|
+
if manifest["confirmable"]:
|
|
285
|
+
out += ["확정하려면 아래 칸에 `확정`을, 돌려보내려면 `반려`와 메모를 적습니다.", "",
|
|
286
|
+
*owner_lines.confirm_block(set_sha(manifest)), ""]
|
|
287
|
+
else:
|
|
288
|
+
out += ["확정할 승인이 없거나 유효한 순서가 없어 이 판에는 확인 칸이 없습니다.", ""]
|
|
289
|
+
text = "\n".join(out)
|
|
290
|
+
found += owner_lines.render_problems(text)
|
|
291
|
+
if found:
|
|
292
|
+
raise Refused("RENDER_INVALID " + "\n".join(found))
|
|
293
|
+
return text
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
# ---- the parts --------------------------------------------------------------------------------------------------
|
|
297
|
+
|
|
298
|
+
def gathered(run_dir):
|
|
299
|
+
"""`(current, approvals, s7b, parses, library)` as the run holds them."""
|
|
300
|
+
run_dir = pathlib.Path(run_dir)
|
|
301
|
+
path = run_dir / f"review.v{stage_approvals.latest_version(run_dir)}.json"
|
|
302
|
+
current = {**records.read_json(path), "_sha256": records.sha256_file(path)}
|
|
303
|
+
library = sorted({u["path"] for u in records.read_json(run_dir / INVENTORY).get("units") or [] if u.get("path")})
|
|
304
|
+
s7b, problems = stage_adjudicate.overlay_review(
|
|
305
|
+
records.read_json(run_dir / stage_review_proposals.OUTPUT),
|
|
306
|
+
stage_adjudicate.read_inputs(run_dir, stage_adjudicate.adjudicated_inputs(run_dir)))
|
|
307
|
+
if problems:
|
|
308
|
+
raise Refused("\n".join(problems))
|
|
309
|
+
return (current, stage_approvals.rows_in(run_dir / stage_approvals.APPROVALS), s7b,
|
|
310
|
+
stage_approvals.parsed_in(run_dir), library)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def versions(run_dir):
|
|
314
|
+
return sorted(int(m.group(1)) for p in (pathlib.Path(run_dir) / "confirm").glob("v*")
|
|
315
|
+
for m in [re.fullmatch(r"v([1-9][0-9]*)", p.name)] if m and (p / "manifest.json").is_file())
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def build(run_dir):
|
|
319
|
+
"""S10b's build part: the next confirmation version, or Refused with nothing written."""
|
|
320
|
+
run_dir = pathlib.Path(run_dir)
|
|
321
|
+
|
|
322
|
+
def unconfirmed():
|
|
323
|
+
# under the stage's lock (`records.run_stage`'s `admit`): checked before it, a confirm that commits between
|
|
324
|
+
# the check and the lock leaves a new version built beside a confirmed set (Codex WP-20 r1 F1)
|
|
325
|
+
if (run_dir / CONFIRMATION).is_file():
|
|
326
|
+
raise Refused(f"CONFIRMED_ALREADY S10b: the final set is confirmed ({CONFIRMATION}); S11 applies it")
|
|
327
|
+
unconfirmed()
|
|
328
|
+
with records.run_stage(run_dir, STAGE, inputs_of(run_dir), part=BUILD, admit=unconfirmed) as stage:
|
|
329
|
+
manifest, problems = final_set(stage.declaration, *gathered(run_dir))
|
|
330
|
+
if problems:
|
|
331
|
+
raise Refused("\n".join(problems))
|
|
332
|
+
if not manifest["approval_ids"]:
|
|
333
|
+
apart = {k: len(manifest[k]) for k in ("awaiting_R", "stale", "needs_proposal", "nothing_to_apply")}
|
|
334
|
+
raise Refused(f"NOTHING_APPROVED S10b: no approval puts an item in the final set (apart: {apart}); decide "
|
|
335
|
+
"the review first")
|
|
336
|
+
version = 1 + max(versions(run_dir), default=0)
|
|
337
|
+
text = page(manifest, version)
|
|
338
|
+
records.write_json(run_dir, run_dir / manifest_rel(version), manifest)
|
|
339
|
+
records.write_text(run_dir, run_dir / render_name(version), text)
|
|
340
|
+
records.write_text(run_dir, run_dir / copy_name(version), owner_lines.copy_of(text, render_name(version)))
|
|
341
|
+
for rel in (manifest_rel(version), render_name(version), copy_name(version)):
|
|
342
|
+
stage.output(rel)
|
|
343
|
+
return {"version": version, "F": len(manifest["F"]), "ledger_only": len(manifest["ledger_only"]),
|
|
344
|
+
"apart": sum(len(manifest[k]) for k in ("awaiting_R", "stale", "needs_proposal", "nothing_to_apply")),
|
|
345
|
+
"confirmable": manifest["confirmable"], "sequenced": manifest["sequencing"].get("sequenced"),
|
|
346
|
+
"copy": copy_name(version)}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def binding_problems(stored, again, manifest_sha, registered_sha):
|
|
350
|
+
"""CONFIRMATION_UNBOUND, by field, for every way the manifest build recorded no longer binds the final set."""
|
|
351
|
+
out = []
|
|
352
|
+
held, now = stored.get("item_shas") or {}, again.get("item_shas") or {}
|
|
353
|
+
for item_id in sorted(set(held) | set(now)):
|
|
354
|
+
if held.get(item_id) != now.get(item_id):
|
|
355
|
+
out.append(f"CONFIRMATION_UNBOUND item_sha {item_id}: the manifest bound "
|
|
356
|
+
f"{str(held.get(item_id))[:12]}, and the current rows carry {str(now.get(item_id))[:12]}")
|
|
357
|
+
if stored.get("configuration_sha") != again.get("configuration_sha"):
|
|
358
|
+
out.append(f"CONFIRMATION_UNBOUND configuration_sha: the manifest bound "
|
|
359
|
+
f"{str(stored.get('configuration_sha'))[:12]}, and F is {str(again.get('configuration_sha'))[:12]} now")
|
|
360
|
+
if manifest_sha != registered_sha:
|
|
361
|
+
out.append("CONFIRMATION_UNBOUND manifest_sha: the manifest on disk is not the one build recorded")
|
|
362
|
+
if stored.get("results") != S8_DEFERRED or again.get("results") != S8_DEFERRED:
|
|
363
|
+
out.append(f"CONFIRMATION_UNBOUND results_sha: release 1's results are {S8_DEFERRED!r}, and the manifest holds "
|
|
364
|
+
f"{stored.get('results')!r}")
|
|
365
|
+
if not out and set_sha(stored) != set_sha(again):
|
|
366
|
+
out.append("CONFIRMATION_UNBOUND manifest: the final set built again is not the one the manifest holds")
|
|
367
|
+
return out
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def schema_problems(doc):
|
|
371
|
+
if not _VALIDATOR:
|
|
372
|
+
_VALIDATOR.append(validate.compile_schema(json.loads(SCHEMA_PATH.read_text(encoding="utf-8"))))
|
|
373
|
+
return [f"SCHEMA_INVALID confirmation: {v}" for v in validate.validate_instance(_VALIDATOR[0], doc)]
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def confirm(run_dir, version=None, copy_path=None):
|
|
377
|
+
"""S10b's confirm part: the owner's copy of the latest version, held to the final set built again."""
|
|
378
|
+
run_dir = pathlib.Path(run_dir)
|
|
379
|
+
held = versions(run_dir)
|
|
380
|
+
if not held:
|
|
381
|
+
raise Refused("CONFIRM_ABSENT S10b: no confirmation version is built; run `confirm` without --decide first")
|
|
382
|
+
version = version or held[-1]
|
|
383
|
+
if version not in held:
|
|
384
|
+
raise Refused(f"VERSION_UNKNOWN v{version}: the confirmation versions are {held}")
|
|
385
|
+
|
|
386
|
+
def undecided():
|
|
387
|
+
# checked again under the stage's lock, before the record is replaced (`records.run_stage`'s `admit`): two
|
|
388
|
+
# invocations could each pass the check made before it, and the second then confirmed a version the first
|
|
389
|
+
# had returned, or one a build had superseded (Codex WP-20 r1 F1)
|
|
390
|
+
if (run_dir / returned_rel(version)).is_file() or (run_dir / CONFIRMATION).is_file():
|
|
391
|
+
raise Refused(f"VERSION_DECIDED_ALREADY v{version}: a confirmation version is decided once, and a run's "
|
|
392
|
+
"final set is confirmed once")
|
|
393
|
+
latest = versions(run_dir)[-1]
|
|
394
|
+
if version != latest:
|
|
395
|
+
raise Refused(f"VERSION_SUPERSEDED v{version}: v{latest} was built after it; decide the latest version")
|
|
396
|
+
undecided()
|
|
397
|
+
specs = inputs_of(run_dir) + [{"artifact": manifest_rel(version), "producer_stage": STAGE},
|
|
398
|
+
{"artifact": render_name(version), "producer_stage": STAGE}]
|
|
399
|
+
with records.run_stage(run_dir, STAGE, specs, part=CONFIRM, admit=undecided) as stage:
|
|
400
|
+
stored = records.read_json(run_dir / manifest_rel(version))
|
|
401
|
+
registered = next((row["sha256"] for row in stage.record["inputs"] if row["artifact"] == manifest_rel(version)),
|
|
402
|
+
None)
|
|
403
|
+
text = (run_dir / render_name(version)).read_text(encoding="utf-8")
|
|
404
|
+
source = pathlib.Path(copy_path) if copy_path else run_dir / copy_name(version)
|
|
405
|
+
try:
|
|
406
|
+
copy_text = source.read_bytes().decode("utf-8")
|
|
407
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
408
|
+
raise Refused(f"COPY_UNREADABLE {source.name}: {type(exc).__name__}; the copy is UTF-8 text") from exc
|
|
409
|
+
result, problems = owner_lines.parse(text, copy_text, render_name=render_name(version),
|
|
410
|
+
confirm_set=set_sha(stored))
|
|
411
|
+
if problems:
|
|
412
|
+
raise Refused("\n".join(problems))
|
|
413
|
+
block = result["confirm"]
|
|
414
|
+
if block is None:
|
|
415
|
+
raise Refused(f"NOTHING_TO_CONFIRM v{version}: the version carries no confirmation block "
|
|
416
|
+
"(nothing approved, or no valid order)")
|
|
417
|
+
if block["state"] == "stale":
|
|
418
|
+
raise Refused(block["code"])
|
|
419
|
+
if block["state"] != "decided":
|
|
420
|
+
raise Refused(f"NOTHING_DECIDED v{version}: write 확인: 확정 or 확인: 반려 in {source.name} first")
|
|
421
|
+
again, found = final_set(stage.declaration, *gathered(run_dir))
|
|
422
|
+
found += binding_problems(stored, again, records.sha256_file(run_dir / manifest_rel(version)), registered)
|
|
423
|
+
if found:
|
|
424
|
+
raise Refused("\n".join(found))
|
|
425
|
+
copy_sha, at = owner_lines.sha256_text(copy_text), records.now()
|
|
426
|
+
if block["decision"] == "return":
|
|
427
|
+
records.write_json(run_dir, run_dir / returned_rel(version),
|
|
428
|
+
{"stage": STAGE, "confirm_version": version, "decision": "return", "note": block["note"],
|
|
429
|
+
"manifest_sha": registered, "decision_input_sha": copy_sha, "at": at})
|
|
430
|
+
stage.output(returned_rel(version))
|
|
431
|
+
return {"version": version, "decision": "return", "approvals": len(stored["approval_ids"])}
|
|
432
|
+
row = {"approval_ids": stored["approval_ids"], "configuration_sha": stored["configuration_sha"],
|
|
433
|
+
"manifest_sha": registered, "results_sha": S8_DEFERRED, "confirm_version": version,
|
|
434
|
+
"decision_input_sha": copy_sha, "at": at}
|
|
435
|
+
doc = {"confirmation_id": "C-" + stage_approvals.sha256_of({k: v for k, v in row.items() if k != "at"})[:16],
|
|
436
|
+
**row}
|
|
437
|
+
problems = schema_problems(doc)
|
|
438
|
+
if problems:
|
|
439
|
+
raise Refused("\n".join(problems))
|
|
440
|
+
records.write_json(run_dir, run_dir / CONFIRMATION, doc)
|
|
441
|
+
stage.output(CONFIRMATION)
|
|
442
|
+
return {"version": version, "decision": "confirm", "approvals": len(stored["approval_ids"]),
|
|
443
|
+
"confirmation_id": doc["confirmation_id"]}
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
# ---- self-test --------------------------------------------------------------------------------------------------
|
|
447
|
+
|
|
448
|
+
def fx_run(root, declaration=None, edit=None, alternative=None):
|
|
449
|
+
"""A run carried to S10's parse over S10's own fixture rows (`stage_approvals.fixture`: a place, a keep, a guarded
|
|
450
|
+
reduce, an item awaiting R, a disputed row and a legacy group), each producer's file written under its own stage
|
|
451
|
+
record, as `stage_propose.fx_through_s6` writes S6's. S10's parse is the real one. Returns the run directory."""
|
|
452
|
+
from runlib import declare, stage_render
|
|
453
|
+
text, rows_doc, frozen, _declaration = stage_approvals.fixture()
|
|
454
|
+
# S11's suite declares a checkout that exists (`declaration`) and gives an operation the state of a real file
|
|
455
|
+
# (`edit(rows_doc)`, before the rows are written)
|
|
456
|
+
if edit:
|
|
457
|
+
edit(rows_doc)
|
|
458
|
+
run_dir = pathlib.Path(root) / "out" / "r1"
|
|
459
|
+
declare.create(run_dir, declaration or declare.fixture())
|
|
460
|
+
with records.run_stage(run_dir, "S2", [], part="inventory") as stage:
|
|
461
|
+
records.write_json(run_dir, run_dir / INVENTORY, {"units": [
|
|
462
|
+
{"unit_id": "u-k", "layer": "catalog", "path": "claude/guides/k.md"}],
|
|
463
|
+
"reference": {"kind": "current", "complete": True, "incomplete_reasons": []}, "layers": []})
|
|
464
|
+
stage.output(INVENTORY)
|
|
465
|
+
with records.run_stage(run_dir, "S7b", []) as stage:
|
|
466
|
+
records.write_json(run_dir, run_dir / stage_review_proposals.OUTPUT, {"stage": "S7b", "reviews": [
|
|
467
|
+
{"item_id": "k-place", "verdict": "disagree", "alternative": alternative or {"disposition": "incubate",
|
|
468
|
+
"reason": "관찰을 더 모은다"}}]})
|
|
469
|
+
stage.output(stage_review_proposals.OUTPUT)
|
|
470
|
+
with records.run_stage(run_dir, "S9", []) as stage:
|
|
471
|
+
records.write_text(run_dir, run_dir / "review.ko.v1.md", text)
|
|
472
|
+
records.write_json(run_dir, run_dir / "review.v1.json", rows_doc)
|
|
473
|
+
records.write_json(run_dir, run_dir / stage_render.frozen_name(1), frozen)
|
|
474
|
+
records.write_text(run_dir, run_dir / "decisions.ko.v1.md", owner_lines.copy_of(text, "review.ko.v1.md"))
|
|
475
|
+
for rel in ("review.ko.v1.md", "review.v1.json", stage_render.frozen_name(1), "decisions.ko.v1.md"):
|
|
476
|
+
stage.output(rel)
|
|
477
|
+
return run_dir
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def self_test():
|
|
481
|
+
"""The suite under the release scope `all`: the contract as designed, which release 1 holds closed
|
|
482
|
+
(`placement.scoped`), so the path the redesign reopens stays held by its controls. Release 1's own controls
|
|
483
|
+
run inside it under `release_1`."""
|
|
484
|
+
with placement.scoped("all"):
|
|
485
|
+
return _self_test_all()
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def _self_test_all():
|
|
489
|
+
"""The final set over S10's fixture first, then its page and its bindings, then a run through S10's real parse and
|
|
490
|
+
both parts, and the driver's `confirm` as a process."""
|
|
491
|
+
import copy
|
|
492
|
+
import shutil
|
|
493
|
+
import subprocess
|
|
494
|
+
import tempfile
|
|
495
|
+
failures, ran, reporting, reached = [], [], [], []
|
|
496
|
+
|
|
497
|
+
def mark(name):
|
|
498
|
+
if reporting:
|
|
499
|
+
raise RuntimeError(f"CONTROL_AFTER_SUMMARY {name}")
|
|
500
|
+
ran.append(name)
|
|
501
|
+
|
|
502
|
+
def equal(name, got, want):
|
|
503
|
+
mark(name)
|
|
504
|
+
if got != want:
|
|
505
|
+
failures.append((name, f"expected {want!r}, got {got!r}"))
|
|
506
|
+
|
|
507
|
+
def control(name, got, want):
|
|
508
|
+
mark(name)
|
|
509
|
+
if not isinstance(got, str):
|
|
510
|
+
raise TypeError(f"CONTROL_GOT_NOT_STR {name}: {type(got).__name__}")
|
|
511
|
+
if want not in got:
|
|
512
|
+
failures.append((name, f"expected {want!r} in {got[:500]!r}"))
|
|
513
|
+
|
|
514
|
+
def attempt(fn, *args, **kwargs):
|
|
515
|
+
try:
|
|
516
|
+
return fn(*args, **kwargs)
|
|
517
|
+
except (Refused, OSError, KeyError, StopIteration, TypeError) as exc: # a reverted check fails by name
|
|
518
|
+
return f"{type(exc).__name__}: {exc}"
|
|
519
|
+
|
|
520
|
+
text, rows_doc, frozen, declaration = stage_approvals.fixture()
|
|
521
|
+
blank = owner_lines.copy_of(text, "review.ko.v1.md")
|
|
522
|
+
|
|
523
|
+
def fill(copy_text, choices):
|
|
524
|
+
held = copy_text.split("\n")
|
|
525
|
+
for item, lines in choices.items():
|
|
526
|
+
start = next(i for i, x in enumerate(held) if x.startswith(f"<!-- owner-block review item={item} "))
|
|
527
|
+
end = next(i for i in range(start + 1, len(held)) if held[i] == owner_lines.CLOSE)
|
|
528
|
+
held = held[:start + 1] + list(lines) + held[end:]
|
|
529
|
+
return "\n".join(held)
|
|
530
|
+
|
|
531
|
+
def parsed(choices, rows=None):
|
|
532
|
+
got = stage_approvals.parse_document(declaration, text, rows_doc, rows or rows_doc, frozen,
|
|
533
|
+
fill(blank, choices), [], "2026-11-12T01:00:00+00:00")
|
|
534
|
+
return got[0], got[2], got[3]
|
|
535
|
+
|
|
536
|
+
offered = {"reviews": [{"item_id": "k-place", "alternative": {"disposition": "incubate", "reason": "다른 말"}}]}
|
|
537
|
+
|
|
538
|
+
def built(choices, rows=None, s7b=None, library=("claude/guides/k.md",)):
|
|
539
|
+
approvals, parse, problems = parsed(choices, rows)
|
|
540
|
+
if problems:
|
|
541
|
+
return {"F": [], "ledger_only": [], "needs_proposal": [], "nothing_to_apply": [], "approval_ids": [],
|
|
542
|
+
"sequencing": {}, "confirmable": None}, problems
|
|
543
|
+
return final_set(declaration, {**(rows or rows_doc), "_sha256": "1" * 64}, approvals,
|
|
544
|
+
offered if s7b is None else s7b, [parse], list(library))
|
|
545
|
+
|
|
546
|
+
approve = {"k-place": ["결정: 승인"], "k-keep": ["결정: 승인"], "k-awaits": ["결정: 승인"],
|
|
547
|
+
"k-reduce": ["결정: 승인", "keep 해제: R-1 사용자가 직접 줄인다"],
|
|
548
|
+
"group:legacy:incubating": ["결정: 승인"]}
|
|
549
|
+
|
|
550
|
+
# ---- positive controls ---------------------------------------------------------------------------------------
|
|
551
|
+
manifest, found = built(approve)
|
|
552
|
+
equal("positive: the fixture's approved set builds with nothing refused", found, [])
|
|
553
|
+
# release 1 changes no library file (D-20261116-7853bc), in the final set itself
|
|
554
|
+
with placement.scoped("release_1"):
|
|
555
|
+
_held, release_found = built(approve)
|
|
556
|
+
quiet_manifest, quiet_found = built({"k-keep": ["결정: 승인"], "group:legacy:incubating": ["결정: 승인"]})
|
|
557
|
+
equal("in release 1 each approved item that changes a library file is refused by name, and nothing else is",
|
|
558
|
+
[p.split(":")[0] for p in release_found],
|
|
559
|
+
["RELEASE_1_NO_LIBRARY_CHANGE S10b k-place", "RELEASE_1_NO_LIBRARY_CHANGE S10b k-reduce"])
|
|
560
|
+
equal("and a set whose approvals change no library file builds with nothing refused and F empty",
|
|
561
|
+
(quiet_found, quiet_manifest["F"], len(quiet_manifest["ledger_only"])), ([], [], 3))
|
|
562
|
+
equal("F is the approved items that change the library, in the review's rank order, and not the one awaiting R",
|
|
563
|
+
[i["item_id"] for i in manifest["F"]], ["k-place", "k-reduce"])
|
|
564
|
+
equal("the ledger-only set is the approved keep and each member of the approved legacy group, under its group",
|
|
565
|
+
sorted((i["item_id"], i["disposition"], i.get("member_of")) for i in manifest["ledger_only"]),
|
|
566
|
+
[("k-keep", "keep", None), ("legacy:L-1", "none", "group:legacy:incubating"),
|
|
567
|
+
("legacy:L-2", "none", "group:legacy:incubating")])
|
|
568
|
+
equal("the approved item awaiting R is apart, by name, and not bound",
|
|
569
|
+
[i["item_id"] for i in manifest["awaiting_R"]], ["k-awaits"])
|
|
570
|
+
approvals, parse, _p = parsed(approve)
|
|
571
|
+
equal("the bound approvals are F's and the ledger-only ones, exactly",
|
|
572
|
+
manifest["approval_ids"], sorted(a["approval_id"] for a in approvals if a["item_id"] != "k-awaits"))
|
|
573
|
+
equal("the configuration is the one S10's parse bound, over the declaration's B and F",
|
|
574
|
+
(manifest["configuration_sha"], manifest["configuration_sha"] == (parse or {}).get("configuration_sha")),
|
|
575
|
+
(stage_approvals.configuration_sha(declaration, manifest["F"]), True))
|
|
576
|
+
equal("release 1's cases and results are the named deferred state, never null",
|
|
577
|
+
(manifest["cases"], manifest["results"]), (S8_DEFERRED, S8_DEFERRED))
|
|
578
|
+
equal("each bound item's sha is the current rows' (a group member's, its group's)",
|
|
579
|
+
manifest["item_shas"], {i: rows_doc["spec"][g]["item_sha"] for i, g in (
|
|
580
|
+
("k-place", "k-place"), ("k-reduce", "k-reduce"), ("k-keep", "k-keep"),
|
|
581
|
+
("legacy:L-1", "group:legacy:incubating"), ("legacy:L-2", "group:legacy:incubating"))})
|
|
582
|
+
equal("F's order is answered over the approved subset from the current library",
|
|
583
|
+
(manifest["sequencing"].get("sequenced"), manifest["sequencing"].get("order"), manifest["confirmable"]),
|
|
584
|
+
(True, ["k-place", "k-reduce"], True))
|
|
585
|
+
|
|
586
|
+
# ---- each rule, one break at a time ----------------------------------------------------------------------------
|
|
587
|
+
m, f = built({**approve, "k-place": ["결정: 수정 대안 s7b"]})
|
|
588
|
+
equal("an adopted S7b incubate carries no observation, so it is S7's to propose again and not in the set (Codex "
|
|
589
|
+
"release-1 review F2)",
|
|
590
|
+
([(i["item_id"], i["disposition"], i["why"]) for i in m["needs_proposal"] if i["item_id"] == "k-place"],
|
|
591
|
+
[i["item_id"] for i in m["ledger_only"] if i["item_id"] == "k-place"], [i["item_id"] for i in m["F"]], f),
|
|
592
|
+
([("k-place", "incubate", "adopted_incubate_without_observation")], [], ["k-reduce"], []))
|
|
593
|
+
dropping = copy.deepcopy(rows_doc)
|
|
594
|
+
next(r for r in dropping["rows"] if r["item_id"] == "k-place")["s7b"]["alternative"] = {
|
|
595
|
+
"disposition": "drop", "reason": "이번 근거로는 약하다"}
|
|
596
|
+
m, f = built({**approve, "k-place": ["결정: 수정 대안 s7b"]}, rows=dropping,
|
|
597
|
+
s7b={"reviews": [{"item_id": "k-place", "alternative": {"disposition": "drop", "reason": "x"}}]})
|
|
598
|
+
equal("an adopted drop joins the ledger-only set with the reason the owner read, which the close records",
|
|
599
|
+
([(i["item_id"], i["disposition"], i.get("adopted"), i.get("alternative_reason")) for i in m["ledger_only"]
|
|
600
|
+
if i["item_id"] == "k-place"], f), ([("k-place", "drop", "s7b", "이번 근거로는 약하다")], []))
|
|
601
|
+
next(r for r in dropping["rows"] if r["item_id"] == "k-place")["s7b"]["alternative"] = {
|
|
602
|
+
"disposition": "drop", "reason": " "}
|
|
603
|
+
m, f = built({**approve, "k-place": ["결정: 수정 대안 s7b"]}, rows=dropping,
|
|
604
|
+
s7b={"reviews": [{"item_id": "k-place", "alternative": {"disposition": "drop", "reason": "x"}}]})
|
|
605
|
+
equal("and one without a reason is S7's to propose again",
|
|
606
|
+
[(i["item_id"], i["why"]) for i in m["needs_proposal"] if i["item_id"] == "k-place"],
|
|
607
|
+
[("k-place", "adopted_without_reason")])
|
|
608
|
+
next(r for r in dropping["rows"] if r["item_id"] == "k-place")["s7b"]["alternative"] = {
|
|
609
|
+
"disposition": "keep", "reason": "지금 것이 맞다"}
|
|
610
|
+
m, f = built({**approve, "k-place": ["결정: 수정 대안 s7b"]}, rows=dropping,
|
|
611
|
+
s7b={"reviews": [{"item_id": "k-place", "alternative": {"disposition": "keep", "reason": "x"}}]})
|
|
612
|
+
equal("and an adopted keep names no units to keep, so it is S7's to propose again, reason or not (round 2 F3)",
|
|
613
|
+
([(i["item_id"], i["why"]) for i in m["needs_proposal"] if i["item_id"] == "k-place"],
|
|
614
|
+
[i["item_id"] for i in m["ledger_only"] if i["item_id"] == "k-place"]),
|
|
615
|
+
([("k-place", "adopted_keep_without_units")], []))
|
|
616
|
+
m, f = built({**approve, "k-place": ["결정: 수정 대안 s7b"]},
|
|
617
|
+
s7b={"reviews": [{"item_id": "k-place", "alternative": {"disposition": "drop"}}]})
|
|
618
|
+
control("an adopted alternative S7b's recorded review no longer offers is ALTERNATIVE_STALE", "\n".join(f),
|
|
619
|
+
"ALTERNATIVE_STALE k-place")
|
|
620
|
+
m, f = built({**approve, "k-place": ["결정: 수정 대안 s7b"]}, s7b={"reviews": []})
|
|
621
|
+
control("and so is one S7b's recorded review does not hold at all", "\n".join(f), "ALTERNATIVE_STALE k-place")
|
|
622
|
+
changing = copy.deepcopy(rows_doc)
|
|
623
|
+
next(r for r in changing["rows"] if r["item_id"] == "k-place")["s7b"]["alternative"] = {"disposition": "place"}
|
|
624
|
+
m, f = built({"k-place": ["결정: 수정 대안 s7b"]}, rows=changing,
|
|
625
|
+
s7b={"reviews": [{"item_id": "k-place", "alternative": {"disposition": "place"}}]})
|
|
626
|
+
equal("an adopted alternative that would change the library goes back to S7, and no approval is bound",
|
|
627
|
+
([(i["item_id"], i["why"]) for i in m["needs_proposal"]], m["approval_ids"], f),
|
|
628
|
+
([("k-place", "adopted_alternative")], [], []))
|
|
629
|
+
m, f = built({"k-place": ["결정: 수정", "메모: 대상을 좁힌다"]})
|
|
630
|
+
equal("a 수정 with its note goes back to S7, apart", [(i["item_id"], i["why"]) for i in m["needs_proposal"]],
|
|
631
|
+
[("k-place", "revise_note")])
|
|
632
|
+
# a disputed row cannot be approved at all (the grammar's DISPUTE_UNRESOLVED); a returned row can, and has nothing
|
|
633
|
+
returned = copy.deepcopy(rows_doc)
|
|
634
|
+
held_row = next(r for r in returned["rows"] if r["item_id"] == "k-keep")
|
|
635
|
+
held_row.update(status="returned", proposal=None)
|
|
636
|
+
m, f = built({"k-keep": ["결정: 승인"]}, rows=returned)
|
|
637
|
+
equal("an approval of a row that carries no proposal binds nothing and is apart, with the row's status",
|
|
638
|
+
([(i["item_id"], i["status"]) for i in m["nothing_to_apply"]], m["approval_ids"], m["ledger_only"], f),
|
|
639
|
+
([("k-keep", "returned")], [], [], []))
|
|
640
|
+
moved = copy.deepcopy(rows_doc)
|
|
641
|
+
next(r for r in moved["rows"] if r["item_id"] == "k-keep")["item_sha"] = "f" * 64
|
|
642
|
+
m, f = final_set(declaration, {**moved, "_sha256": "2" * 64}, approvals, offered, [parse], ["claude/guides/k.md"])
|
|
643
|
+
equal("an approval the current rows made stale is apart, by name, and not bound",
|
|
644
|
+
([i["item_id"] for i in m["stale"]], any(i["item_id"] == "k-keep" for i in m["ledger_only"]),
|
|
645
|
+
len(m["approval_ids"])), (["k-keep"], False, 4))
|
|
646
|
+
m, f = final_set(declaration, {**rows_doc, "_sha256": "1" * 64}, approvals, offered,
|
|
647
|
+
[{**parse, "configuration_sha": "0" * 64}], ["claude/guides/k.md"])
|
|
648
|
+
control("a last parse that bound another F is CONFIRMATION_UNBOUND configuration_sha", "\n".join(f),
|
|
649
|
+
"CONFIRMATION_UNBOUND configuration_sha: the last parse (v1)")
|
|
650
|
+
m, f = final_set(declaration, {**rows_doc, "_sha256": "1" * 64}, approvals, offered, [], ["claude/guides/k.md"])
|
|
651
|
+
control("and so is a run with no committed parse", "\n".join(f), "CONFIRMATION_UNBOUND configuration_sha")
|
|
652
|
+
# the order, on the approved subset alone (plan WP-20 done-when 6: the full set valid, the subset not)
|
|
653
|
+
routed = copy.deepcopy(rows_doc)
|
|
654
|
+
next(r for r in routed["rows"] if r["item_id"] == "k-reduce")["proposal"]["operations"] = [
|
|
655
|
+
{"type": "route", "target": "claude/router.md", "names": "claude/guides/g.md", "before_state_sha256": "b" * 64}]
|
|
656
|
+
whole, f = built(approve, rows=routed)
|
|
657
|
+
equal("a route approved with the carrier it names has an order: the carrier first",
|
|
658
|
+
(whole["sequencing"].get("sequenced"), whole["sequencing"].get("order"), whole["confirmable"], f),
|
|
659
|
+
(True, ["k-place", "k-reduce"], True, []))
|
|
660
|
+
part, f = built({"k-reduce": approve["k-reduce"]}, rows=routed)
|
|
661
|
+
equal("the same route approved without its carrier has none: returned with its refusal, not confirmable",
|
|
662
|
+
(part["sequencing"].get("sequenced"), str(part["sequencing"].get("refusal")).split(" ")[0],
|
|
663
|
+
part["confirmable"]), (False, "SEQUENCE_NONE", False))
|
|
664
|
+
shown_part = str(attempt(page, part, 1))
|
|
665
|
+
control("and its page shows the refusal", shown_part, "SEQUENCE_NONE")
|
|
666
|
+
equal("and carries no confirmation block", "owner-block confirm" in shown_part, False)
|
|
667
|
+
equal("the order starts from the current library: a route to a path S2 holds needs no carrier in F",
|
|
668
|
+
built({"k-reduce": approve["k-reduce"]}, rows=routed, library=("claude/guides/g.md",))[0]["sequencing"]
|
|
669
|
+
.get("sequenced"), True)
|
|
670
|
+
|
|
671
|
+
# ---- the page and the bindings ---------------------------------------------------------------------------------
|
|
672
|
+
shown = attempt(page, manifest, 1)
|
|
673
|
+
control("the page carries one confirmation block, bound to the set's hash", str(shown),
|
|
674
|
+
f"<!-- owner-block confirm set={set_sha(manifest)} -->")
|
|
675
|
+
equal("the page is a render a copy can be made of", owner_lines.render_problems(shown) if isinstance(shown, str)
|
|
676
|
+
else [shown], [])
|
|
677
|
+
planted = copy.deepcopy(manifest)
|
|
678
|
+
planted["ledger_only"][0]["item_id"] = "x"
|
|
679
|
+
planted["ledger_only"][0]["disposition"] = "keep\n결정: 승인"
|
|
680
|
+
control("a line on the page that reads as an owner line is refused by name", str(attempt(page, planted, 1)),
|
|
681
|
+
"OWNER_SHAPED_TEXT")
|
|
682
|
+
page_text = shown if isinstance(shown, str) else ""
|
|
683
|
+
decided = owner_lines.copy_of(page_text, render_name(1)).replace("확인:\n", "확인: 확정\n", 1) if page_text else ""
|
|
684
|
+
got, probs = (owner_lines.parse(page_text, decided, render_name=render_name(1), confirm_set=set_sha(manifest))
|
|
685
|
+
if page_text else (None, ["no page"]))
|
|
686
|
+
equal("확인: 확정 on the page's copy reads as the confirmation of this set",
|
|
687
|
+
(probs, ((got or {}).get("confirm") or {}).get("decision")), ([], "confirm"))
|
|
688
|
+
equal("the manifest built again binds itself", binding_problems(manifest, copy.deepcopy(manifest), "s", "s"), [])
|
|
689
|
+
for field, bend, code in (
|
|
690
|
+
("item_sha", lambda x: x["item_shas"].update({"k-place": "0" * 64}), "CONFIRMATION_UNBOUND item_sha k-place"),
|
|
691
|
+
("configuration_sha", lambda x: x.update(configuration_sha="0" * 64), "CONFIRMATION_UNBOUND configuration_sha"),
|
|
692
|
+
("results_sha", lambda x: x.update(results="0" * 64), "CONFIRMATION_UNBOUND results_sha"),
|
|
693
|
+
("manifest", lambda x: x["ledger_only"].pop(), "CONFIRMATION_UNBOUND manifest:")):
|
|
694
|
+
bent = copy.deepcopy(manifest)
|
|
695
|
+
bend(bent)
|
|
696
|
+
control(f"a stale {field} is refused by field", "\n".join(binding_problems(bent, manifest, "s", "s")), code)
|
|
697
|
+
control("manifest bytes that are not the ones build recorded are refused by field",
|
|
698
|
+
"\n".join(binding_problems(manifest, manifest, "a" * 64, "b" * 64)), "CONFIRMATION_UNBOUND manifest_sha")
|
|
699
|
+
schema = json.loads(SCHEMA_PATH.read_text(encoding="utf-8"))
|
|
700
|
+
equal("the confirmation schema's required set is §10.3's list and the plan's additions",
|
|
701
|
+
sorted(schema["required"]), sorted(DESIGN_10_3_CONFIRMATION + PLAN_CONFIRMATION_ADDS))
|
|
702
|
+
good = {"confirmation_id": "C-" + "0" * 16, "approval_ids": ["A-" + "0" * 16], "configuration_sha": "0" * 64,
|
|
703
|
+
"manifest_sha": "0" * 64, "results_sha": S8_DEFERRED, "confirm_version": 1, "decision_input_sha": "0" * 64,
|
|
704
|
+
"at": "2026-11-12T01:00:00+00:00"}
|
|
705
|
+
equal("a confirmation in its schema's shape passes it", schema_problems(good), [])
|
|
706
|
+
control("one with null results is refused by the schema", "\n".join(schema_problems({**good, "results_sha": None})),
|
|
707
|
+
"SCHEMA_INVALID confirmation: results_sha")
|
|
708
|
+
|
|
709
|
+
# ---- the run: S10's real parse, both parts, and the driver as a process ----------------------------------------
|
|
710
|
+
class SectionStopped(Exception):
|
|
711
|
+
"""Raised only after the control that says why the section cannot go on: a StopIteration from a helper is an
|
|
712
|
+
ordinary failure of this section, never a silent end of it."""
|
|
713
|
+
root = pathlib.Path(tempfile.mkdtemp(prefix="s10b-"))
|
|
714
|
+
try:
|
|
715
|
+
run_dir = attempt(fx_run, root)
|
|
716
|
+
if isinstance(run_dir, str):
|
|
717
|
+
equal("the run through S10's parse is made", run_dir[:300], "a run")
|
|
718
|
+
raise SectionStopped
|
|
719
|
+
copy_path = run_dir / "decisions.ko.v1.md"
|
|
720
|
+
copy_path.write_text(fill(copy_path.read_text(encoding="utf-8"), approve), encoding="utf-8")
|
|
721
|
+
got = attempt(stage_approvals.run, run_dir, 1)
|
|
722
|
+
equal("S10's real parse commits the owner's decisions", getattr(got, "get", lambda k: got)("decided"), 5)
|
|
723
|
+
before = shutil.copytree(root / "out", root / "before-build")
|
|
724
|
+
done = attempt(build, run_dir)
|
|
725
|
+
equal("build writes version 1: two items in F, three ledger-only, one apart, confirmable",
|
|
726
|
+
{k: done.get(k) for k in ("version", "F", "ledger_only", "apart", "confirmable")}
|
|
727
|
+
if isinstance(done, dict) else done,
|
|
728
|
+
{"version": 1, "F": 2, "ledger_only": 3, "apart": 1, "confirmable": True})
|
|
729
|
+
rec = ((records.stage_records(run_dir).get(STAGE) or {}).get("parts") or {}).get(BUILD) or {}
|
|
730
|
+
equal("S10b's build part records the manifest, the page and the copy, and reads what it names",
|
|
731
|
+
(rec.get("status"), sorted(o["artifact"] for o in rec.get("outputs") or []),
|
|
732
|
+
sorted(i["artifact"] for i in rec.get("inputs") or [])),
|
|
733
|
+
("complete", sorted([manifest_rel(1), render_name(1), copy_name(1)]),
|
|
734
|
+
sorted(["review.v1.json", "approvals.jsonl", "review-s7b.json", INVENTORY, "parsed.v1.json"])))
|
|
735
|
+
page_text = (run_dir / render_name(1)).read_text(encoding="utf-8")
|
|
736
|
+
# whole lines (Codex WP-20 r2 F6): the effect sentence, the section's heading and each item's own line
|
|
737
|
+
equal("the page says, in one line, what confirming does under the design's scope",
|
|
738
|
+
[line for line in page_text.split("\n") if line.startswith("확정하면 S11이")], ['확정하면 S11이 이 집합에서 파일을 바꾸는 항목(F)만 선언된 체크아웃에 적용합니다. `none`(바꾸지 않음)과 대장에만 남는 처리(keep·incubate·drop)는 파일을 바꾸지 않습니다. 커밋과 설치는 소유자가 직접 합니다 — 적용으로 파일이 바뀌면 실행할 명령을 그대로 보여 드립니다.'])
|
|
739
|
+
equal("the items without a file change are headed as such, not as ledger changes",
|
|
740
|
+
[line for line in page_text.split("\n") if line.startswith("## ") and "바꾸" in line],
|
|
741
|
+
["## 라이브러리를 바꾸는 항목 (F)", "## 파일을 바꾸지 않는 항목"])
|
|
742
|
+
kept_page = page({**records.read_json(run_dir / manifest_rel(1)), "ledger_only": [
|
|
743
|
+
{"item_id": "k-new", "approval_id": "a1", "disposition": "none"},
|
|
744
|
+
{"item_id": "legacy:L-1", "approval_id": "a2", "disposition": "none"},
|
|
745
|
+
{"item_id": "k-keep2", "approval_id": "a3", "disposition": "keep"}]}, 9)
|
|
746
|
+
equal("each item without a file change says where it is kept: a new candidate's none in the run's record "
|
|
747
|
+
"alone, a legacy entry's none and a keep in the ledger (F-40)",
|
|
748
|
+
[line for line in kept_page.split("\n") if line.startswith(("- k-new", "- legacy:L-1", "- k-keep2"))],
|
|
749
|
+
["- k-new: none — 이번 실행 기록에만 남음", "- legacy:L-1: none — 대장에 기록", "- k-keep2: keep — 대장에 기록"])
|
|
750
|
+
equal("a none on a new candidate is kept in the run's record alone, one on a legacy entry and a keep are not "
|
|
751
|
+
"(F-40)", [kept_in_run_only(i) for i in ({"item_id": "k-x", "disposition": "none"},
|
|
752
|
+
{"item_id": "legacy:L-1", "disposition": "none"},
|
|
753
|
+
{"item_id": "due_decision:N-1@r1", "disposition": "none"},
|
|
754
|
+
{"item_id": "k-x", "disposition": "keep"})],
|
|
755
|
+
[True, False, False, False])
|
|
756
|
+
control("an undecided copy confirms nothing", str(attempt(confirm, run_dir)), "NOTHING_DECIDED v1")
|
|
757
|
+
later = shutil.copytree(root / "out", root / "later")
|
|
758
|
+
again = attempt(build, later / "r1")
|
|
759
|
+
equal("building again before the owner decides makes a new version", getattr(again, "get", lambda k: again)(
|
|
760
|
+
"version"), 2)
|
|
761
|
+
control("and the earlier version is not decided", str(attempt(confirm, later / "r1", 1)), "VERSION_SUPERSEDED v1")
|
|
762
|
+
cli_root = shutil.copytree(root / "out", root / "cli")
|
|
763
|
+
returned_root = shutil.copytree(root / "out", root / "returned")
|
|
764
|
+
moved_root = shutil.copytree(root / "out", root / "moved")
|
|
765
|
+
race_root = shutil.copytree(root / "out", root / "race")
|
|
766
|
+
race_build_root = shutil.copytree(root / "out", root / "race-build")
|
|
767
|
+
# an input moved after build: the shared record check refuses before any field is read
|
|
768
|
+
m_run = moved_root / "r1"
|
|
769
|
+
m_copy = m_run / copy_name(1)
|
|
770
|
+
m_copy.write_text(m_copy.read_text(encoding="utf-8").replace("확인:\n", "확인: 확정\n", 1), encoding="utf-8")
|
|
771
|
+
held = records.read_json(m_run / manifest_rel(1))
|
|
772
|
+
(m_run / manifest_rel(1)).write_text(json.dumps({**held, "results": "0" * 64}), encoding="utf-8")
|
|
773
|
+
control("a manifest edited after build is refused before anything is confirmed", str(attempt(confirm, m_run)),
|
|
774
|
+
f"INPUT_INVALID S10b.build: {manifest_rel(1)} is not the output S10b.build recorded")
|
|
775
|
+
equal("and nothing is confirmed", (m_run / CONFIRMATION).exists(), False)
|
|
776
|
+
# the owner confirms
|
|
777
|
+
c_copy = run_dir / copy_name(1)
|
|
778
|
+
c_copy.write_text(c_copy.read_text(encoding="utf-8").replace("확인:\n", "확인: 확정\n", 1), encoding="utf-8")
|
|
779
|
+
done = attempt(confirm, run_dir)
|
|
780
|
+
conf = records.read_json(run_dir / CONFIRMATION) if (run_dir / CONFIRMATION).is_file() else {}
|
|
781
|
+
stored = records.read_json(run_dir / manifest_rel(1))
|
|
782
|
+
equal("확인: 확정 writes the confirmation: the bound approval ids, F's configuration, the manifest's sha and the "
|
|
783
|
+
"deferred results", (done.get("decision") if isinstance(done, dict) else done, conf.get("approval_ids"),
|
|
784
|
+
conf.get("configuration_sha"), conf.get("manifest_sha"), conf.get("results_sha")),
|
|
785
|
+
("confirm", stored.get("approval_ids"), stored.get("configuration_sha"),
|
|
786
|
+
records.sha256_file(run_dir / manifest_rel(1)), S8_DEFERRED))
|
|
787
|
+
equal("the confirmed approval ids are approvals.jsonl's, and include none awaiting R", sorted(
|
|
788
|
+
a["approval_id"] for a in stage_approvals.rows_in(run_dir / stage_approvals.APPROVALS)
|
|
789
|
+
if a["item_id"] != "k-awaits"), conf.get("approval_ids"))
|
|
790
|
+
control("a version is decided once", str(attempt(confirm, run_dir)), "VERSION_DECIDED_ALREADY v1")
|
|
791
|
+
control("a confirmed run builds no new version", str(attempt(build, run_dir)), "CONFIRMED_ALREADY S10b")
|
|
792
|
+
# 반려 is not a confirmation
|
|
793
|
+
b_run = returned_root / "r1"
|
|
794
|
+
b_copy = b_run / copy_name(1)
|
|
795
|
+
b_copy.write_text(b_copy.read_text(encoding="utf-8").replace("확인:\n메모:\n", "확인: 반려\n메모: 다시 본다\n", 1),
|
|
796
|
+
encoding="utf-8")
|
|
797
|
+
done = attempt(confirm, b_run)
|
|
798
|
+
equal("확인: 반려 with its note is returned, and no confirmation is written",
|
|
799
|
+
(done.get("decision") if isinstance(done, dict) else done, (b_run / CONFIRMATION).exists(),
|
|
800
|
+
(records.read_json(b_run / returned_rel(1)) if (b_run / returned_rel(1)).is_file() else {}).get("note")),
|
|
801
|
+
("return", False, "다시 본다"))
|
|
802
|
+
again = attempt(build, b_run)
|
|
803
|
+
equal("after 반려 a new version is built", getattr(again, "get", lambda k: again)("version"), 2)
|
|
804
|
+
control("and the returned version is not decided again", str(attempt(confirm, b_run, 1)),
|
|
805
|
+
"VERSION_DECIDED_ALREADY v1")
|
|
806
|
+
# Codex WP-20 r1 F1: another invocation's decision lands after this one's first check and before its lock.
|
|
807
|
+
# The stand-in writes that decision as the lock is about to be taken; only the check under the lock sees it.
|
|
808
|
+
real_run_stage = records.run_stage
|
|
809
|
+
|
|
810
|
+
def racing(run_dir_, stage_, *args, **kwargs):
|
|
811
|
+
if kwargs.get("part") == CONFIRM:
|
|
812
|
+
(pathlib.Path(run_dir_) / returned_rel(1)).write_text(json.dumps({"decision": "return"}),
|
|
813
|
+
encoding="utf-8")
|
|
814
|
+
if kwargs.get("part") == BUILD:
|
|
815
|
+
(pathlib.Path(run_dir_) / CONFIRMATION).write_text("{}", encoding="utf-8")
|
|
816
|
+
return real_run_stage(run_dir_, stage_, *args, **kwargs)
|
|
817
|
+
r_run = race_root / "r1"
|
|
818
|
+
r_copy = r_run / copy_name(1)
|
|
819
|
+
r_copy.write_text(r_copy.read_text(encoding="utf-8").replace("확인:\n", "확인: 확정\n", 1), encoding="utf-8")
|
|
820
|
+
records.run_stage = racing
|
|
821
|
+
try:
|
|
822
|
+
lost = str(attempt(confirm, r_run))
|
|
823
|
+
lost_build = str(attempt(build, race_build_root / "r1"))
|
|
824
|
+
finally:
|
|
825
|
+
records.run_stage = real_run_stage
|
|
826
|
+
control("a return committed after confirm's first check is seen under the stage's lock", lost,
|
|
827
|
+
"VERSION_DECIDED_ALREADY v1")
|
|
828
|
+
equal("and no confirmation is written beside it", (r_run / CONFIRMATION).exists(), False)
|
|
829
|
+
control("a confirmation committed after build's first check is seen under the stage's lock", lost_build,
|
|
830
|
+
"CONFIRMED_ALREADY S10b")
|
|
831
|
+
equal("and no version is built beside it", versions(race_build_root / "r1"), [1])
|
|
832
|
+
# Codex WP-20 r1 F5: S9 renders S7b's review with S10's second-pass review laid over it, so S10b reads it so
|
|
833
|
+
adj = attempt(fx_run, root / "adj")
|
|
834
|
+
if isinstance(adj, str):
|
|
835
|
+
equal("the run for the adjudicated overlay is made", adj[:300], "a run")
|
|
836
|
+
raise SectionStopped
|
|
837
|
+
with records.run_stage(adj, "S10", [], part=stage_adjudicate.PART) as stage:
|
|
838
|
+
names = stage_adjudicate.outputs_of(1)
|
|
839
|
+
for rel, doc in zip(names, ({"newly_admitted": ["k-place"], "verdicts": {}},
|
|
840
|
+
{"proposals": [{"candidate_id": "k-place"}], "returned": []},
|
|
841
|
+
{"reviews": [{"item_id": "k-place", "verdict": "disagree",
|
|
842
|
+
"alternative": {"disposition": "none", "reason": "다시 봄"}}]})):
|
|
843
|
+
records.write_json(adj, adj / rel, doc)
|
|
844
|
+
stage.output(rel)
|
|
845
|
+
seen = attempt(gathered, adj)
|
|
846
|
+
equal("S10b reads S7b's review with the adjudicated second-pass review laid over it, as S9 rendered it",
|
|
847
|
+
[((r.get("alternative") or {}).get("disposition")) for r in (seen[2] if isinstance(seen, tuple) else {})
|
|
848
|
+
.get("reviews") or [] if r.get("item_id") == "k-place"] if isinstance(seen, tuple) else seen, ["none"])
|
|
849
|
+
equal("and declares the adjudicated versions among its inputs",
|
|
850
|
+
sorted(set(stage_adjudicate.outputs_of(1)) & {i["artifact"] for i in inputs_of(adj)}),
|
|
851
|
+
sorted(stage_adjudicate.outputs_of(1)))
|
|
852
|
+
# a run whose decisions approve nothing the final set can hold is refused, and nothing is built
|
|
853
|
+
lone = attempt(fx_run, root / "lone")
|
|
854
|
+
if isinstance(lone, str):
|
|
855
|
+
equal("the second run through S10's parse is made", lone[:300], "a run")
|
|
856
|
+
raise SectionStopped
|
|
857
|
+
lone_copy = lone / "decisions.ko.v1.md"
|
|
858
|
+
lone_copy.write_text(fill(lone_copy.read_text(encoding="utf-8"), {"k-awaits": ["결정: 승인"]}), encoding="utf-8")
|
|
859
|
+
attempt(stage_approvals.run, lone, 1)
|
|
860
|
+
control("a run whose only approval awaits R builds nothing", str(attempt(build, lone)),
|
|
861
|
+
"NOTHING_APPROVED S10b: no approval puts an item in the final set (apart: {'awaiting_R': 1")
|
|
862
|
+
equal("and writes no version", versions(lone), [])
|
|
863
|
+
# the driver, as a process, at the release scope it ships with: release 1 refuses a set that changes a library
|
|
864
|
+
# file at the build and at the owner's decision, and builds and confirms one that changes none
|
|
865
|
+
fresh = shutil.copytree(before, root / "cli-build")
|
|
866
|
+
said = subprocess.run([sys.executable, "-I", str(HERE / "distill.py"), "confirm", "--run-id", "r1",
|
|
867
|
+
"--out", str(fresh)], capture_output=True, text=True, timeout=600)
|
|
868
|
+
control("the driver's `confirm`, a process in release 1, refuses a set that changes a library file, by item",
|
|
869
|
+
f"rc={said.returncode} {said.stdout}{said.stderr[-400:]}", "rc=1 RELEASE_1_NO_LIBRARY_CHANGE S10b k-place")
|
|
870
|
+
equal("and builds no version", versions(fresh / "r1"), [])
|
|
871
|
+
k_copy = cli_root / "r1" / copy_name(1)
|
|
872
|
+
k_copy.write_text(k_copy.read_text(encoding="utf-8").replace("확인:\n", "확인: 확정\n", 1), encoding="utf-8")
|
|
873
|
+
said = subprocess.run([sys.executable, "-I", str(HERE / "distill.py"), "confirm", "--run-id", "r1",
|
|
874
|
+
"--out", str(cli_root), "--decide"], capture_output=True, text=True, timeout=600)
|
|
875
|
+
control("and its `confirm --decide` refuses to confirm a version built with one (under the design's scope)",
|
|
876
|
+
f"rc={said.returncode} {said.stdout}{said.stderr[-400:]}", "rc=1 RELEASE_1_NO_LIBRARY_CHANGE S10b k-place")
|
|
877
|
+
equal("and no confirmation is written", (cli_root / "r1" / CONFIRMATION).is_file(), False)
|
|
878
|
+
quiet = attempt(fx_run, root / "cli-quiet")
|
|
879
|
+
if isinstance(quiet, str):
|
|
880
|
+
equal("the run whose approvals change no library file is made", quiet[:300], "a run")
|
|
881
|
+
raise SectionStopped
|
|
882
|
+
quiet_copy = quiet / "decisions.ko.v1.md"
|
|
883
|
+
quiet_copy.write_text(fill(quiet_copy.read_text(encoding="utf-8"), {
|
|
884
|
+
"k-keep": ["결정: 승인"], "group:legacy:incubating": ["결정: 승인"]}), encoding="utf-8")
|
|
885
|
+
attempt(stage_approvals.run, quiet, 1)
|
|
886
|
+
said = subprocess.run([sys.executable, "-I", str(HERE / "distill.py"), "confirm", "--run-id", "r1",
|
|
887
|
+
"--out", str(quiet.parent)], capture_output=True, text=True, timeout=600)
|
|
888
|
+
control("the driver's `confirm` in release 1 builds a set that changes no library file, F empty",
|
|
889
|
+
f"rc={said.returncode} {said.stdout}{said.stderr[-400:]}",
|
|
890
|
+
"rc=0 S10b confirm: version 1 built, 0 in F, 3 ledger-only, 0 apart")
|
|
891
|
+
quiet_page = (quiet / render_name(1)).read_text(encoding="utf-8") if (quiet / render_name(1)).is_file() else ""
|
|
892
|
+
equal("and its page says what confirming does in release 1, and not that S11 applies anything",
|
|
893
|
+
([line for line in quiet_page.split("\n") if line == owner_lines.RELEASE_1_CONFIRM_EFFECT],
|
|
894
|
+
[line for line in quiet_page.split("\n") if "S11이 이 집합을" in line or "S11이 이 집합에서" in line]),
|
|
895
|
+
([owner_lines.RELEASE_1_CONFIRM_EFFECT], []))
|
|
896
|
+
q_copy = quiet / copy_name(1)
|
|
897
|
+
if q_copy.is_file():
|
|
898
|
+
q_copy.write_text(q_copy.read_text(encoding="utf-8").replace("확인:\n", "확인: 확정\n", 1), encoding="utf-8")
|
|
899
|
+
said = subprocess.run([sys.executable, "-I", str(HERE / "distill.py"), "confirm", "--run-id", "r1",
|
|
900
|
+
"--out", str(quiet.parent), "--decide"], capture_output=True, text=True, timeout=600)
|
|
901
|
+
control("and its `confirm --decide` confirms the owner's copy as a process",
|
|
902
|
+
f"rc={said.returncode} {said.stdout}{said.stderr[-400:]}", "rc=0 S10b confirm: version 1 confirmed")
|
|
903
|
+
equal("and the confirmation is written", (quiet / CONFIRMATION).is_file(), True)
|
|
904
|
+
reached.append(True)
|
|
905
|
+
except SectionStopped:
|
|
906
|
+
pass
|
|
907
|
+
except Exception as exc: # a later break fails this section by name, never the whole suite
|
|
908
|
+
failures.append(("the run section ran to its end", f"{type(exc).__name__}: {exc}"[:600]))
|
|
909
|
+
finally:
|
|
910
|
+
shutil.rmtree(root, ignore_errors=True)
|
|
911
|
+
|
|
912
|
+
if not reached and not failures:
|
|
913
|
+
failures.append(("the run section ran to its end", "it stopped with no failure named"))
|
|
914
|
+
reporting.append(True)
|
|
915
|
+
if failures:
|
|
916
|
+
for label, detail in failures:
|
|
917
|
+
print(f"stage_confirm --self-test [FAIL] {label}: {detail}", file=sys.stderr)
|
|
918
|
+
print(f"stage_confirm --self-test: FAILED ({len(failures)} of {len(ran)} controls)", file=sys.stderr)
|
|
919
|
+
return 1
|
|
920
|
+
print(f"stage_confirm --self-test: OK ({len(ran)} controls: the final set from S10's approvals, F, the ledger-only "
|
|
921
|
+
f"and the apart, each by name; the adopted alternative held to S7b; the order on the approved subset; the "
|
|
922
|
+
f"page's block bound to the set; the confirmation bound by field; 반려 not a confirmation)")
|
|
923
|
+
return 0
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
if __name__ == "__main__":
|
|
927
|
+
if sys.argv[1:] == ["--self-test"]:
|
|
928
|
+
sys.exit(self_test())
|
|
929
|
+
sys.exit("usage: stage_confirm.py --self-test")
|