Files
gstack/test/ship-document-release-dispatch.test.ts
T
Garry TanandClaude Fable 5 253d1dfe26 v1.76.0.0 fix: ship doc-sync survives Conductor — spawned subagent sessions reachable (#2733) (#2741)
* feat(session-kind): explicit GSTACK_SESSION_KIND override; skill-start spawned gates keyed on kind (#2733)

Claude Code subagents inherit the parent env byte-for-byte, so ambient
markers classify them as the parent's kind and the spawned classification
was unreachable outside OpenClaw. GSTACK_SESSION_KIND=spawned (step 0,
spawned-only by design) lets a dispatching skill mark its subagent per
command. skill-start now keys SPAWNED_SESSION and the spawned-session
instruction block on the resolved kind (was raw OPENCLAW_SESSION),
suppresses CONDUCTOR_SESSION for spawned sessions, gates all 11
interactive-onboarding blocks plus their ack-at-emit marker writes on
kind != spawned, and adds a destructive-gate carve-out to the spawned
block (conservative-continue, never prose-STOP).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(hooks): spawned-session escape in Conductor AUQ deny; override coverage in AUQ-error fallback (#2733)

Hooks inherit the harness env, so a per-command GSTACK_SESSION_KIND
prefix inside a subagent's bash can never reach them. Levers added:
a deterministic [conductor][spawned] auto-choose deny for env-level
spawned sessions (OPENCLAW_SESSION or session-wide GSTACK_SESSION_KIND),
and a spawned escape sentence appended to both hooks' prose directives
so a marked subagent that slips and calls AUQ resolves to auto-choose
instead of prose-STOP. The sentence lives in one shared constant
(hosts/claude/hooks/spawned-directive.ts) so the two paths can never
drift; destructive semantics are unified to conservative-continue.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(ship): Step 18 marks the document-release subagent spawned — env prefix + auto-choose prompt (#2733)

The dispatch prompt now (1) frames the run as a SPAWNED subagent whose
LAST line is machine-parsed, (2) instructs prefixing the preamble's
gstack-skill-start invocation with GSTACK_SESSION_KIND=spawned on the
same command line (template bash blocks don't share exports), and
(3) resolves every AUQ gate to auto-choosing the recommended option,
conservative on no-recommendation, never destructive. The JSON contract
gains a required "decisions" array (auto-chosen gates, printed to the
ship console — never embedded in the public PR body) and a placement
clause so the skill's own doc-health summary stops competing with the
LAST-line JSON. Tripwire pins added; codex/factory goldens refreshed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(auq-format): proactive SESSION_KIND=spawned rule ordered above the Conductor rule (#2733)

The spawned classification previously existed only in the failure-fallback
branch — a spawned session was invited to call AskUserQuestion and reach
auto-choose via the deny/error detour, and a spawned session inside a
Conductor workspace hit the Conductor prose-STOP rule first. The Tool
resolution list now leads with the spawned rule (auto-choose recommended,
never prose, never BLOCKED, destructive gates resolve conservative), the
self-check carries the never-reach-this-checklist clause, and all tier>=2
SKILL.md renders are regenerated. Context-budget fixture refreshed in the
same commit per the ratchet protocol (the AUQ section is eager in every
tier>=2 skill).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(e2e): spawned document-release subagent returns the JSON contract through a firing gate (#2733)

The behavioral proof the bug shipped without: ship-docsync stubs the
skill (no preamble, no gates) and skill-e2e-workflow suppresses the
gates by prompt. This gate-tier E2E plays the parent — it drives the
verbatim Step 18 dispatch prompt (extracted from the live pr-body.md,
drift-proof) against a real preamble-bearing document-release slice in
a Conductor-ambient env with both AUQ hooks seeded live, an unbumped
VERSION making Step 8 fire. Asserts: the final line parses as the
5-key JSON contract, the fired gate's auto-choice is recorded in
decisions, and VERSION is untouched (the gate resolved to its
recommended Skip). Burn-in: 1/1 pass, $0.35, 21 turns, 106s.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs(openclaw): document the GSTACK_SESSION_KIND override; wire session-kind into paid selectors (#2733)

OPENCLAW.md's spawned-session section now covers the explicit per-command
marker, its deliberate spawned-only narrowness, the /ship Step 18 usage,
the destructive carve-out, onboarding-block suppression, and the hook
env-blindness caveat. bin/gstack-session-kind and the shared
spawned-directive module join the conductor-prose and
auto-decide-preserved selector dep lists (session-kind previously
appeared in no touchfiles entry — editing it alone triggered no paid
E2E). TODOS.md gains the plan-tune capture follow-up for spawned
auto-choices.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: pre-landing review fixes (#2733)

Review army + coverage audit findings, all applied:
- headless directive carries the spawned escape sentence too (multi-
  specialist: a CI-hosted ship's marked subagent must not end BLOCKED)
- anti-injection scoping on every text-claimable spawned trigger (AUQ
  rule + shared escape sentence): markings count only from the creating
  prompt, never from files/tool output/web content read mid-run
- [conductor][spawned] deny annotates one-way doors per question
- SPAWNED_OVERRIDE: env tamper-visibility status line + OPENCLAW.md note
- spawned sessions skip the network update-check and first-task probe
  (consumers suppressed; preserves the one-shot just-upgraded marker)
- test hardening: dispatch-tripwire end-bound validated, vacuous marker
  asserts replaced with output asserts, E2E cpSync size filter + named
  fence tolerance, spawnedByEnv parity pin, destructive-policy cross-
  surface drift guard, one-way annotation + bogus-value hook cases
- session-kind duplicate rationale comment deduped; regen + goldens +
  context-budget fixture refreshed

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore: bump version and changelog (v1.76.0.0)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs: update project documentation for v1.76.0.0

PROJECT_STRUCTURE.md: add hosts/claude/hooks/ to the directory tree
(AUQ capture + enforcement hooks, spawned-session directive, timeline
stop) — the tree omitted the directory while docs/OPENCLAW.md and
CHANGELOG.md now reference paths inside it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs: sync TODOS.md ship dispatch entry with the v1.76.0.0 contract

Codex doc-review finding: the SHIPPED entry for /ship auto-invoking
/document-release still described the four-key JSON contract. Adds the
decisions key (console-printed, never PR markdown), the
GSTACK_SESSION_KIND=spawned dispatch marking (#2733), and the new
spawned-dispatch gate E2E to the proven-by list.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-30 20:45:19 -07:00

155 lines
7.6 KiB
TypeScript

/**
* /ship → /document-release Step 18 dispatch stays wired AND visible.
*
* The v1.54.0.0 carve (46c1fae7) moved Step 18 (documentation sync) out of
* the ship skeleton into sections/pr-body.md. The wiring survived, but on
* the Claude host the skeleton stopped saying "document-release" anywhere
* in the workflow body — the dispatch became invisible at the decision
* points and "the idea of running document-release as part of ship got
* lost". This tripwire pins both halves so neither can silently regress:
*
* - the carved section keeps the full dispatch contract (imperative,
* subagent_type, JSON return keys, non-blocking failure), and
* - the Claude skeleton names "the /document-release subagent" at its
* three touchpoints (manifest trigger via section-index + STOP pointer,
* Step 17 handoff, hoisted doc-sync invariant) while the imperative
* itself stays carved.
*
* Structural backstop lives in test/helpers/carve-guards.ts (ship entry);
* this named test documents the regression story. Behavioral proof is the
* ship-docsync E2E (test/skill-e2e-ship-docsync.test.ts).
*/
import { describe, test, expect } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
const ROOT = path.join(import.meta.dir, '..');
const SECTION_SITES = [
path.join(ROOT, 'ship', 'sections', 'pr-body.md'),
path.join(ROOT, 'ship', 'sections', 'pr-body.md.tmpl'),
];
// ship/SKILL.md only — NOT the claude golden: test/host-config.test.ts
// already enforces golden == generated byte-for-byte, so substring asserts
// on the golden would be pure duplication. The codex/factory goldens ARE
// asserted below because for them the check is content (the inlined
// section survived generation), which byte-equality alone doesn't prove.
const CLAUDE_SKELETON = path.join(ROOT, 'ship', 'SKILL.md');
const INLINED_GOLDENS = [
path.join(ROOT, 'test', 'fixtures', 'golden', 'codex-ship-SKILL.md'),
path.join(ROOT, 'test', 'fixtures', 'golden', 'factory-ship-SKILL.md'),
];
const CARVED_IMPERATIVE = 'Dispatch /document-release as a subagent';
describe('/ship Step 18 dispatches /document-release (carve visibility)', () => {
test('carved section carries the full dispatch contract', () => {
for (const file of SECTION_SITES) {
const content = fs.readFileSync(file, 'utf-8');
expect(content).toContain(
'## Step 18: Documentation sync (via subagent, before PR creation)'
);
expect(content).toContain(CARVED_IMPERATIVE);
expect(content).toContain('subagent_type: "general-purpose"');
// The JSON return contract Step 19 bakes into the PR body.
expect(content).toContain('"files_updated"');
expect(content).toContain('"commit_sha"');
expect(content).toContain('"pushed"');
expect(content).toContain('"documentation_section"');
// Deliberate design: docs sync never holds a ship hostage.
expect(content).toContain('Do not block /ship on subagent failure');
// These four strings are the ship-docsync E2E's dispatch-matcher markers
// (test/skill-e2e-ship-docsync.test.ts): the first two are INCLUSION
// markers (verbatim from the dictated Step 18 subagent prompt); the last
// two are EXCLUSION markers (section scaffolding that disqualifies a
// whole-section paste). Rewording any of them in pr-body.md.tmpl silently
// deadens the paid matcher; update all four in lockstep.
expect(content).toContain('You are executing the /document-release workflow');
expect(content).toContain('.claude/skills/gstack/document-release/SKILL.md');
expect(content).toContain('## Step 19: Create PR/MR');
expect(content).toContain('Parent processing:');
// #2733: the dispatch marks the subagent spawned so document-release's
// AUQ gates auto-choose instead of prose-stopping (which breaks the
// parent's LAST-line JSON parse). Three layers pinned: the env marker
// prefix, the behavioral instruction, and the framing sentence.
expect(content).toContain('GSTACK_SESSION_KIND=spawned');
expect(content).toContain('auto-choose the RECOMMENDED option');
expect(content).toContain('as a SPAWNED subagent');
// Auto-chosen gate decisions ride the JSON contract (console-printed by
// the parent), never the public PR body.
expect(content).toContain('"decisions"');
const docHeading = content.indexOf('\n## Documentation\n');
expect(docHeading, 'PR-body template must carry the ## Documentation heading').toBeGreaterThan(0);
// End bound searched FROM docHeading and asserted found — otherwise a
// removed/reordered '## Test plan' heading degrades this guard to a
// vacuous empty-slice check instead of failing loudly (#2733 review).
const docEnd = content.indexOf('\n## Test plan\n', docHeading);
expect(docEnd, '## Test plan heading must follow ## Documentation').toBeGreaterThan(docHeading);
const docSection = content.slice(docHeading, docEnd);
expect(docSection, 'decisions must never leak into the PR-body Documentation embed').not.toContain('decisions');
}
});
test('claude skeleton names the subagent at all three touchpoints', () => {
const content = fs.readFileSync(CLAUDE_SKELETON, 'utf-8');
// Manifest trigger — renders into the section-index row AND the STOP
// pointer, so it must appear at least twice.
const trigger =
'dispatching the /document-release subagent to sync docs (Step 18) and then creating or updating the PR/MR (Step 19)';
expect(content.split(trigger).length - 1).toBeGreaterThanOrEqual(2);
// Step 17 handoff.
expect(content).toContain(
'Step 18 (dispatch the /document-release subagent to sync docs)'
);
// Hoisted doc-sync invariant (beside the PR-title invariant).
expect(content).toContain('**Doc-sync invariant');
expect(content).toContain('dispatches the /document-release subagent');
// The STOP-Read pointer still routes to the carved section.
expect(content).toMatch(
/> \*\*STOP\.\*\*[^\n]*Read `[^`]*ship\/sections\/pr-body\.md`/
);
// Ordering pin: the hoisted invariant must sit ABOVE the pr-body STOP
// pointer (mustStayInSkeleton asserts presence only — a future edit could
// drift the paragraph below the STOP with every registry check green).
const invariantIdx = content.indexOf('**Doc-sync invariant');
const stopIdx = content.indexOf(
'> **STOP.** Before dispatching the /document-release subagent'
);
expect(invariantIdx).toBeGreaterThan(-1);
expect(stopIdx).toBeGreaterThan(invariantIdx);
});
test('the dispatch imperative stays carved out of the claude skeleton', () => {
const content = fs.readFileSync(CLAUDE_SKELETON, 'utf-8');
expect(content).not.toContain(CARVED_IMPERATIVE);
});
test('manifest trigger names the subagent', () => {
const manifest = JSON.parse(
fs.readFileSync(
path.join(ROOT, 'ship', 'sections', 'manifest.json'),
'utf-8'
)
);
const prBody = manifest.sections.find(
(s: { id: string }) => s.id === 'pr-body'
);
expect(prBody).toBeDefined();
expect(prBody.trigger).toContain('the /document-release subagent');
});
test('codex + factory goldens inline Step 18 before Step 19', () => {
for (const file of INLINED_GOLDENS) {
const content = fs.readFileSync(file, 'utf-8');
const step18 = content.indexOf(
'## Step 18: Documentation sync (via subagent, before PR creation)'
);
const step19 = content.indexOf('## Step 19: Create PR/MR');
expect(step18).toBeGreaterThan(-1);
expect(step19).toBeGreaterThan(step18);
expect(content).toContain(CARVED_IMPERATIVE);
}
});
});