Skip to content

Commit 7d50fb8

Browse files
committed
test(pm): drive label-write's comment strokes through the real sendFleetWrite
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jR91pcCzC1k9n3p5ah
1 parent 6924440 commit 7d50fb8

1 file changed

Lines changed: 98 additions & 3 deletions

File tree

‎scripts/pm/label-write.mjs‎

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@
248248

249249
import process from 'node:process';
250250
import { spawnSync } from 'node:child_process';
251-
import { readFileSync } from 'node:fs';
251+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
252+
import { tmpdir } from 'node:os';
253+
import { join } from 'node:path';
252254
import { fileURLToPath } from 'node:url';
253255

254256
import { isEntrypoint } from '../invoked-as.mjs';
@@ -1828,6 +1830,61 @@ function fakeRelay(board, outcome = 'success', sent = []) {
18281830
};
18291831
}
18301832

1833+
/**
1834+
* The REAL transport shape: fleet-write's own `sendFleetWrite` — its dispatch POST, its run poll, its body
1835+
* read-back with whatever judge this file hands it — over a fake `fetch` that answers from THE SAME fake board
1836+
* (the dispatch applies the stroke as the executor would, through `fakeRelay`). Only the network, the clock, the
1837+
* sleeps and the throttle file are fake, so a read-back that cannot settle under the real send cannot settle
1838+
* here either. Every send is raced against a wall-clock ceiling: an unsettled promise answers `never-settled`
1839+
* instead of draining the event loop.
1840+
*/
1841+
const REAL_TRANSPORT_CEILING_MS = 15_000;
1842+
function realTransport(board, sent = []) {
1843+
const apply = fakeRelay(board, 'success', []);
1844+
const at = board.serverNow ?? Date.UTC(2026, 10, 8, 15, 0, 0);
1845+
const dir = mkdtempSync(join(tmpdir(), 'label-write-real-transport-'));
1846+
let requestId = null;
1847+
const headers = new Headers({ 'x-ratelimit-remaining': '4999' });
1848+
const answer = (status, json) => ({ status, headers, json: async () => json });
1849+
const RUN = () => ({ id: 42, display_title: `fleet-write ${requestId}`, name: 'Fleet Write', html_url: 'https://github.test/run/42', status: 'completed', conclusion: 'success' });
1850+
const fetchImpl = async (url, init = {}) => {
1851+
const u = new URL(url);
1852+
const method = init.method ?? 'GET';
1853+
if (method === 'POST' && u.pathname.endsWith('/dispatches')) {
1854+
const payload = JSON.parse(init.body).client_payload;
1855+
requestId = payload.request_id;
1856+
await apply(payload);
1857+
return answer(204, null);
1858+
}
1859+
if (method !== 'GET') return answer(405, { message: 'self-test: the real transport writes nothing but the dispatch' });
1860+
if (u.pathname.endsWith('/actions/runs')) return answer(200, { total_count: 1, workflow_runs: [RUN()] });
1861+
if (/\/actions\/runs\/42$/u.test(u.pathname)) return answer(200, RUN());
1862+
if (/\/issues\/\d+\/comments$/u.test(u.pathname)) return answer(200, Number(u.searchParams.get('page') ?? '1') > 1 ? [] : board.comments);
1863+
return answer(404, { message: 'Not Found' });
1864+
};
1865+
const send = async (payload, opts = {}) => {
1866+
sent.push(payload);
1867+
let timer;
1868+
const ceiling = new Promise((resolve) => {
1869+
timer = setTimeout(() => resolve({ state: 'never-settled', ok: false, requestId: payload.request_id, run: null, status: 204, verdict: 'ok', detail: `sendFleetWrite did not settle within ${REAL_TRANSPORT_CEILING_MS} ms` }), REAL_TRANSPORT_CEILING_MS);
1870+
});
1871+
const real = sendFleetWrite(payload, {
1872+
...opts,
1873+
fetch: fetchImpl,
1874+
now: () => at,
1875+
sleep: async () => {},
1876+
ceilings: { startMs: 90_000, ceilingMs: 300_000, pollMs: 5_000, notes: [] },
1877+
pace: { file: join(dir, 'pace.jsonl'), env: { OS_PM_WRITE_MIN_GAP_MS: '0' }, log: () => {}, exit: (code) => { throw new Error(`self-test: the throttle refused with exit ${code}`); } },
1878+
});
1879+
try {
1880+
return await Promise.race([real, ceiling]);
1881+
} finally {
1882+
clearTimeout(timer);
1883+
}
1884+
};
1885+
return { send, sent, cleanup: () => rmSync(dir, { recursive: true, force: true }) };
1886+
}
1887+
18311888
async function driveOffline(argv, boardInit = {}, extra = {}) {
18321889
const fake = fakeBoard(boardInit);
18331890
const parsed = parseOptions(argv);
@@ -1871,7 +1928,7 @@ const silentCard = (serverNowHoursAfterKnock, extra = {}) => ({
18711928
const RELEASE_ARGV = ['--repo', 'objectstack-ai/objectstack', '--issue', '7', '--release', '--recheck-comment', '200', '--comment-file', RELEASE_FILE, '--resume-from', `${RELEASE_BRANCH}@abcdef1234`];
18721929

18731930
async function driveRelease(argv, boardInit, extra = {}) {
1874-
const fake = fakeBoard(boardInit);
1931+
const fake = extra.board ?? fakeBoard(boardInit);
18751932
const parsed = parseOptions(argv);
18761933
if (!parsed.ok) return { parsed, exit: EXIT_USAGE, fake, out: [], sent: [], text: '' };
18771934
const out = [];
@@ -1910,6 +1967,7 @@ export async function relayMissProbe({ route, send }) {
19101967
// that stops registering cases is the bug; a pinned TOTAL would hide it the
19111968
// moment a sibling battery grows (#13489, the shape post-stamped.mjs carries).
19121969
const FOLD_BATTERY = "the fold: a claim (comment + labels + assignee) and a verdict (comment + pr_ready + automerge_enable) as ONE relay stroke, the comment judged on post-stamped's path, every part read back on its own line, a part that fails read-back exit 4 and never repaired, RELAY-ONLY";
1970+
const REAL_TRANSPORT_BATTERY = "the real transport: a comment-bearing stroke (a fold, a release) through fleet-write's own sendFleetWrite — fake fetch, real dispatch, real read-back — settles, exit 0, every ④ line printed";
19131971
const KIND_BATTERY = 'the kind rule: no pm state added to a pull request, no `pm:awaiting-merge` added to an issue, a removal never refused, an unreadable kind refused — on both write paths, before the transport';
19141972
const SELF_TEST_BATTERIES = Object.freeze({
19151973
'the re-exec guard: the name this tool sets, and the patrol name that must not silence it': 11,
@@ -1926,8 +1984,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
19261984
'the relay transport: ONE dispatch carrying the whole stroke, the same read-back, and an accepted dispatch with no run UNCONFIRMED under auto too — never a direct write': 14,
19271985
'the release: a silent claim reclaimed in ONE relay stroke — Release: comment → pm:queue on → pm:dispatched off → unassign — on the knock\'s SERVER-clock age, RELAY-ONLY, never a direct write': 32,
19281986
[FOLD_BATTERY]: 24,
1987+
[REAL_TRANSPORT_BATTERY]: 4,
19291988
});
1930-
const SELF_TEST_BATTERY_FLOOR = 14;
1989+
const SELF_TEST_BATTERY_FLOOR = 15;
19311990
const UNATTRIBUTED_BATTERY = '(unattributed)';
19321991

19331992
const batteryCases = new Map();
@@ -2406,6 +2465,42 @@ export async function selfTest() {
24062465
t('↔ the procedure text sends a claim and a landing through the fold, so a seat reads ONE stroke where it used to read two', [duties.includes('--comment-file'), landing.includes('--land')], [true, true]);
24072466
}
24082467

2468+
// ── the real transport ───────────────────────────────────────────────────
2469+
battery(REAL_TRANSPORT_BATTERY);
2470+
{
2471+
const SESSION = 'session_01ABCDEFGHJKMNPQRSTVWXYZ';
2472+
const route = { requested: 'auto', transport: 'dispatch', reason: 'self-test: dispatch', error: null, session: SESSION };
2473+
const SIG = `domain:skills#2 · os-justin · ${SESSION}`;
2474+
const CLAIM_FILE = '/tmp/self-test/claim.md';
2475+
const CLAIM = `${SIG}\nClaim: PM loop round 1 · {{NOW}}\nSession: \`${SESSION}\`\nBranch: \`claude/issue-7-fold\`\nSeat: \`domain:skills#2\`\nClause-②: no\n`;
2476+
const at = Date.UTC(2026, 10, 8, 15, 0, 0);
2477+
const claimArgv = ['--repo', 'objectstack-ai/objectstack', '--issue', '7', '--add', 'pm:dispatched', '--remove', 'pm:queue', '--assign', 'dev', '--comment-file', CLAIM_FILE];
2478+
const board = fakeBoard({ labels: ['pm:queue', 'domain:skills'], assignees: [], serverNow: at });
2479+
const wire = realTransport(board.board);
2480+
const out = [];
2481+
let fold;
2482+
try {
2483+
const parsed = parseOptions(claimArgv);
2484+
fold = await runLabelWrite(parsed.options, { call: board.call, log: (l) => out.push(l), route, send: wire.send, readText: () => CLAIM, now: () => new Date(at) });
2485+
} finally {
2486+
wire.cleanup();
2487+
}
2488+
const text = out.join('\n');
2489+
t('⭐ a FOLD through the real sendFleetWrite SETTLES: its read-back of the comment completes, ONE dispatch, exit 0', [fold.relay?.state, fold.exit, wire.sent.length], ['success', EXIT_OK, 1], text.slice(-600));
2490+
t('…and label-write\'s own ④ lines print after it, the comment found by its stored bytes', ['④ labels ✓', '④ assignees ✓', '④ comment ✓', '④ MATCHES'].map((l) => text.includes(l)), [true, true, true, true]);
2491+
2492+
const releaseBoard = fakeBoard(silentCard(13));
2493+
const releaseWire = realTransport(releaseBoard.board);
2494+
let rel;
2495+
try {
2496+
rel = await driveRelease(RELEASE_ARGV, silentCard(13), { send: releaseWire.send, board: releaseBoard });
2497+
} finally {
2498+
releaseWire.cleanup();
2499+
}
2500+
t('⭐ a RELEASE through the real sendFleetWrite SETTLES too: ONE dispatch, exit 0', [rel.res?.relay?.state, rel.exit, releaseWire.sent.length], ['success', EXIT_OK, 1], rel.text.slice(-600));
2501+
t('…and its ④ comment line prints', rel.text.includes('④ comment ✓') || rel.text.includes('comment ✓'), true, rel.text.slice(-600));
2502+
}
2503+
24092504
// ── the floor, BEFORE the verdict ────────────────────────────────────────
24102505
const declared = Object.keys(SELF_TEST_BATTERIES);
24112506
const floor = [];

0 commit comments

Comments
 (0)