fix(trekendsession): Phase 3 re-reads the arguments instead of splicing the label into the shell line

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-26 16:12:44 +01:00
commit 89975a1fd6
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
5 changed files with 223 additions and 15 deletions

View file

@ -382,3 +382,38 @@ test("[ARG] the guard's added lines are ASCII", () => {
assert.match(block, /VOYAGE_ARGS_EOF_7F3C9E/);
assert.doesNotMatch(block, /[^\x00-\x7f]/, 'a hook script is ASCII (~/.claude/CLAUDE.md, Miljo)');
});
// The four parser heredoc blocks the commands ship, as Claude Code runs them
// after it substitutes $ARGUMENTS and ${CLAUDE_PLUGIN_ROOT}: a block the guard
// refuses would disable its command while every other test stays green.
// [file, the heading the section starts with]
const SHIPPED_ARGS_BLOCKS = [
['commands/trekendsession.md', '## Phase 0 '],
['commands/trekendsession.md', '## Phase 3 '],
['commands/trekcontinue.md', '## Phase 0 '],
['commands/trekreview.md', '## Phase 1 '],
];
/** The ```bash blocks of the `## ` section of `rel` that starts with `heading` (fence-aware). */
function sectionBashBlocks(rel, heading) {
const lines = readFileSync(join(ROOT, rel), 'utf8').split('\n');
const s = lines.findIndex((l) => l.startsWith(heading));
assert.ok(s !== -1, `${rel} must hold a heading starting "${heading}"`);
let e = lines.length;
let fenced = false;
for (let i = s + 1; i < lines.length; i++) {
if (/^\s{0,3}(`{3,}|~{3,})/.test(lines[i])) fenced = !fenced;
if (!fenced && lines[i].startsWith('## ')) { e = i; break; }
}
const section = lines.slice(s, e).join('\n');
return section.split('\n```bash\n').slice(1).map((b) => b.split('\n```')[0]);
}
test('[ARG] every shipped parser heredoc block passes the guard', async () => {
for (const [rel, heading] of SHIPPED_ARGS_BLOCKS) {
const blocks = sectionBashBlocks(rel, heading).filter((b) => b.includes(`<<'${ARGS_DELIM}'`));
assert.equal(blocks.length, 1, `${rel} ${heading.trim()} must hold one \`\`\`bash block with the parser heredoc <<'${ARGS_DELIM}'; found ${blocks.length}`);
const command = blocks[0].split('$ARGUMENTS').join('brief.md Session 2 of 3').split('${CLAUDE_PLUGIN_ROOT}').join(ROOT);
await expectArgsAllowed(command);
}
});