From 67fc302b84886e198ffc7cb67ff1e939d7f00115 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 04:26:06 -0600 Subject: [PATCH] test(claimant): pin prompt.md constants to claimant.py/poll.py by sync check (#8366) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Route (b) from the issue, per the triage recommendation: prompt.md is hand-tuned prose, so instead of generating it, test_prompt_constants.py fails when any machine-checkable restatement drifts from the code — the drift the #7772 audit repaired by hand (stale queue-CLI path vs REPO_QUEUE_CMD). Pinned: the four queue names, REPO_QUEUE_CMD path, the 36 concurrency cap (both statements), the OpenCode server URL, both launched-by recovery markers, the 30-min activity window and 2-h zombie threshold, mode/fire-log paths, the worker name, route defaults, held-issue labels, and the primary clone — plus claimant/poll cross-module equality for the shared constants. The test docstring carries the full inventory with exemptions and reasons (provider-wall marker, credential-adjacent paths, poll-internal tuning). Wired into run_hermetic_tests.py; test_harness_safety fixture stubs the new module like the existing suites. Deliberate mismatch verified: CONCURRENCY_CAP 36->37 in claimant.py only makes the check fail; reverting restores green. Suites: hermetic 154 OK, test_harness_safety OK, test_claimant/test_poll/test_claimant_args/test_launch_one/test_dispatch_batch/test_send_to_opencode all OK. --- .../opencode-claimant/run_hermetic_tests.py | 1 + .../opencode-claimant/test_harness_safety.py | 1 + .../test_prompt_constants.py | 135 ++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 pm-stack/opencode-claimant/test_prompt_constants.py diff --git a/pm-stack/opencode-claimant/run_hermetic_tests.py b/pm-stack/opencode-claimant/run_hermetic_tests.py index e0290c8037..68f810d79d 100644 --- a/pm-stack/opencode-claimant/run_hermetic_tests.py +++ b/pm-stack/opencode-claimant/run_hermetic_tests.py @@ -58,6 +58,7 @@ def load(name, path): ("offline_claimant", ROOT / "test_claimant.py"), ("offline_poll", ROOT / "test_poll.py"), ("offline_mode", ROOT / "test" / "test_claimant.py"), + ("offline_prompt_constants", ROOT / "test_prompt_constants.py"), ): suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(load(name, path))) result = unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/pm-stack/opencode-claimant/test_harness_safety.py b/pm-stack/opencode-claimant/test_harness_safety.py index c92b5bf73f..111b27eec8 100644 --- a/pm-stack/opencode-claimant/test_harness_safety.py +++ b/pm-stack/opencode-claimant/test_harness_safety.py @@ -35,6 +35,7 @@ def run_harness(self, script, arguments=(), injected_test=None): (source / "test_claimant.py").write_text(injected_test) (source / "test_poll.py").write_text("") (source / "test/test_claimant.py").write_text("") + (source / "test_prompt_constants.py").write_text("") env = dict( os.environ, HOME=str(home), diff --git a/pm-stack/opencode-claimant/test_prompt_constants.py b/pm-stack/opencode-claimant/test_prompt_constants.py new file mode 100644 index 0000000000..bc7dbaf57e --- /dev/null +++ b/pm-stack/opencode-claimant/test_prompt_constants.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +"""Pin prompt.md's restated constants to claimant.py / poll.py (#8366). + +Route chosen: pin-by-check (the issue's option b). prompt.md is +hand-tuned prose; generating it would churn the text operators read, +while this suite fails the moment any machine-checkable restatement +drifts from the code — the exact failure the #7772 Phase 4 audit had +to repair by hand (prompt.md's queue-CLI path was stale in two +places against REPO_QUEUE_CMD). + +Inventory of prompt.md's machine-checkable restatements — each is +either pinned below or exempted here with a reason: + +PINNED (prompt.md restatement -> code constant): +- the four queue names -> claimant.QUEUES == poll.QUEUES +- queue CLI path ~/.local/bin/repo-queue -> claimant.REPO_QUEUE_CMD + == poll.REPO_QUEUE_CMD +- concurrency cap 36 -> claimant.CONCURRENCY_CAP == poll.CAP +- OpenCode server URL http://127.0.0.1:13420 -> claimant.OPENCODE_URL + == poll.OPENCODE_URL +- launched-by recovery markers (zero-message-deleted, gone-session) + -> claimant.LAUNCHED_BY_RECOVERY_ZERO_MESSAGE / + LAUNCHED_BY_RECOVERY_GONE_SESSION +- 30-minute activity window -> poll.ACTIVE_WINDOW_MS +- 2-hour zombie threshold -> poll.ACTIVE_SET_STALE_MS +- mode file path -> claimant.MODE_FILE +- fire-log path -> claimant.FIRES_FILE +- worker name opencode-claimant -> claimant.CLAIMANT_WORKER +- route defaults (provider opencode-route, model workhorse) + -> claimant.LAUNCH_MODEL_PROVIDER / LAUNCH_MODEL_ID +- held-issue labels -> claimant.HELD_ISSUE_LABELS +- primary clone ~/git/code -> claimant.PRIMARY_CLONE + == poll.PRIMARY_CLONE + +EXEMPT (in the code, deliberately not restated in prompt.md): +- LAUNCHED_BY_RECOVERY_PROVIDER_WALL: an internal recovery marker; + the prompt's recovery flow covers only the zero-message and + gone-session cases an operator session performs by hand. +- BROKER_URL_FILE / BROKER_TOKEN_FILE / AUTH_FILE paths: + credential-adjacent; the prompt states the rule (no credential + value or path enters a prompt) instead of the paths. +- LIST_LIMIT, SESSION_FETCH_LIMITS, LEDGER_DB, TURSO_EXEC, the + UUID-lane regex: poll.py implementation tuning with no + operator-facing restatement to drift. + +Run: python3 -m unittest pm-stack/opencode-claimant/test_prompt_constants.py +Also wired into run_hermetic_tests.py. +""" + +import importlib.util +import re +import unittest +from pathlib import Path + +HERE = Path(__file__).resolve().parent + + +def _load(name, filename): + spec = importlib.util.spec_from_file_location(name, HERE / filename) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +claimant = _load("claimant_for_prompt_check", "claimant.py") +poll = _load("poll_for_prompt_check", "poll.py") + +# Whitespace-normalized prompt text: line wrapping in the prose must +# not matter, only the stated values. +PROMPT = re.sub(r"\s+", " ", (HERE / "prompt.md").read_text()) + + +def home_rel(path): + """Render a HOME_DIR-based path the way prompt.md states it.""" + return "~/" + str(path.relative_to(claimant.HOME_DIR)) + + +class PromptConstantsTest(unittest.TestCase): + def test_queue_list_matches_both_modules(self): + self.assertEqual(claimant.QUEUES, poll.QUEUES) + stated = set(re.findall(r"repo-health-[a-z]+-pilot", PROMPT)) + self.assertEqual(stated, set(claimant.QUEUES)) + + def test_queue_cli_path(self): + self.assertEqual(claimant.REPO_QUEUE_CMD, poll.REPO_QUEUE_CMD) + self.assertIn(home_rel(claimant.REPO_QUEUE_CMD), PROMPT) + + def test_concurrency_cap(self): + cap = claimant.CONCURRENCY_CAP + self.assertEqual(cap, poll.CAP) + self.assertEqual(cap, poll.CONCURRENCY_CAP) + m = re.search(r"Concurrency cap: \*\*(\d+)\*\*", PROMPT) + self.assertIsNotNone(m, "prompt.md no longer states the cap") + self.assertEqual(int(m.group(1)), cap) + m = re.search(r"Never exceed the (\d+)-slot claimant cap", PROMPT) + self.assertIsNotNone(m, "prompt.md hard rules no longer state the cap") + self.assertEqual(int(m.group(1)), cap) + + def test_server_url(self): + self.assertEqual(claimant.OPENCODE_URL, poll.OPENCODE_URL) + self.assertIn(claimant.OPENCODE_URL, PROMPT) + + def test_launched_by_recovery_markers(self): + self.assertIn(claimant.LAUNCHED_BY_RECOVERY_ZERO_MESSAGE, PROMPT) + self.assertIn(claimant.LAUNCHED_BY_RECOVERY_GONE_SESSION, PROMPT) + + def test_activity_windows(self): + self.assertEqual(poll.ACTIVE_WINDOW_MS, 30 * 60 * 1000) + self.assertIn("30 min", PROMPT) + self.assertIn("30-minute", PROMPT) + self.assertEqual(poll.ACTIVE_SET_STALE_MS, 2 * 60 * 60 * 1000) + self.assertIn("silent past 2 h", PROMPT) + + def test_state_paths(self): + self.assertIn(home_rel(claimant.MODE_FILE), PROMPT) + self.assertIn(home_rel(claimant.FIRES_FILE), PROMPT) + + def test_worker_name(self): + self.assertIn(f"--worker {claimant.CLAIMANT_WORKER}", PROMPT) + + def test_route_defaults(self): + self.assertIn(f'providerID: "{claimant.LAUNCH_MODEL_PROVIDER}"', PROMPT) + self.assertIn(f'modelID: "{claimant.LAUNCH_MODEL_ID}"', PROMPT) + + def test_held_labels(self): + for label in claimant.HELD_ISSUE_LABELS: + self.assertIn(f"`{label}`", PROMPT) + + def test_primary_clone(self): + self.assertEqual(claimant.PRIMARY_CLONE, poll.PRIMARY_CLONE) + self.assertIn(home_rel(claimant.PRIMARY_CLONE), PROMPT) + + +if __name__ == "__main__": + unittest.main()