A first version's public copy keeps out the owner's short quotes, and phone first-use checks install a build the phone can run (GST-3646) (#4772)

A first version's public export now keeps out the owner's short quotes
and his reasons to leave something out, and a phone first-use check
installs a build the cloud phone can actually run.

Why: a one- or two-word quote or a leave-out reason could reach the
public copy through the gate's choice titles, and the phone check named
a TestFlight build the cloud phone can't install.

Phone checks now need `--phone-build ` on `gstack-first-use start`;
phone runs started before this change must be started again.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p2/specialist-batched#1 reader=security
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-24 04:19:06 +00:00
1 parent 7c321fff5d
commit 84b4eab0a9
10 files changed
+139 -22

No files matched your search

+70
View File
@@ -458,3 +458,73 @@ describe('every attribution, line and quote shape reads as the merge base read i
});
});
describe("short owner quotes and leave-out reasons stay out of a first-version export (GST-3646)", () => {
const tag = (prefix: string, i: number) => `${prefix}${String.fromCharCode(97 + Math.floor(i / 26))}${String.fromCharCode(97 + (i % 26))}vel`;
const QUOTES: Array<[string, (u: string) => string]> = [
['one word', u => u],
['two words', u => `quimbly ${u}`],
['an emoji and a word', u => `🚀 ${u}`],
['CJK', u => `毎朝ベル${u}`],
];
const LINES: Array<[string, (r: string) => string, boolean]> = [
['does it', () => ' → does it', false],
['a choice with a size', () => ' → choice; size: one day', false],
['a one-word reason to leave it out', r => ` → choice; size: two days; leave out: ${r}`, true],
['a two-word reason to leave it out', r => ` → choice; leave out: blint ${r}`, true],
['a longer reason to leave it out', r => ` -> choice; size: one day; leave out: ${r} plinkwort drazzle fippery`, true],
['a reason after extra spaces', r => ` → choice; leave out : ${r}`, true],
['a reason after a capitalized key', r => ` → choice; Leave Out: ${r}`, true],
['does it in mixed case', () => ' → Does It', false],
['a choice and size in mixed case', () => ' → Choice; Size: one day', false],
['a recommended reason in mixed case', r => ` → CHOICE; size: two days; Recommend Leave Out: ${r}`, true],
];
const ROWS = QUOTES.flatMap(([qName, quote], a) => LINES.map(([lName, line, hasReason], b) => {
const i = a * LINES.length + b, reason = tag('rz', i);
const words = quote(tag('qx', i));
return { name: `${qName} / ${lName}`, bullet: `- The owner, 2026-11-20 08:${String(i).padStart(2, '0')}Z: "${words}"${line(reason)}`, words, reason: hasReason ? line(reason).replace(/^.*leave out\s*:\s*/i, '') : undefined };
}));
const plan = [
'# Morning helper (synthetic first version)', '', '## Implementation plan', '',
'Add a morning summary job in lib/morning.ts that reads the calendar and sends one notification.', '',
"### Owner's words", '', ...ROWS.map(row => row.bullet), '',
'### Day one', '', '| action | frequency | source | feature | route | first build | check |', '|---|---|---|---|---|---|---|',
'| reads the morning summary | daily | owner words 1 | Summary | notification | build 1 | the summary lists today |', '',
"### What it won't do yet", '', '- No weekly digest', '', '## Review record', ''].join('\n');
const fragments = (q: string) => [...new Set([...q.split(/\s+/), ...wordKey(q).trim().split(' ')].filter(w => [...w].length >= 3))];
const exported = () => {
const dir = path.join(r.host.base, `owner${++n}`);
const out = path.join(dir, 'run');
expect(r.ap(['next', '--out', out, '--plan', writePlan(dir, plan), '--no-ui', '--no-dx', '--first-version']).status).toBe(0);
phaseVia(r, out, 'ceo', { native: [{ id: 'F1', severity: 'Medium', title: 'The summary does less than the owner asked', changes: 'scope', narrows_quote: 1 }], outside: [] });
expect(phaseVia(r, out, 'eng', { native: [], outside: [] }).outside.stdout).toContain('status=gate_pending');
const pub = path.join(dir, 'public');
const e = r.ap(['export', '--out', out, '--public', pub]);
expect(e.status, e.stderr).toBe(0);
return { out, pub };
};
test('every short quote and every reason to leave one out reaches the gate, and none leaves a 3+ character fragment in the public bytes', () => {
expect(parseOwnerWords(plan).quotes).toHaveLength(ROWS.length);
const { out, pub } = exported();
const gate = JSON.stringify(gateOf(out).items);
expect(ROWS.filter(row => !gate.includes(row.words) && !/does it/i.test(row.bullet)).map(row => row.name)).toEqual([]);
expect(ROWS.filter(row => row.reason && !gate.includes(row.reason)).map(row => row.name)).toEqual([]);
const bytes = allText(pub);
const leaks = ROWS.flatMap(row => [row.words, ...(row.reason ? [row.reason] : [])].flatMap(q => fragments(q).filter(w => bytes.includes(w)).map(w => `${row.name}: ${w}`)));
expect(leaks).toEqual([]);
});
test('validate --public --private catches a short quote or a leave-out reason written back in quote marks, and passes the plain words', () => {
const { out, pub } = exported();
const record = path.join(pub, 'review-record.md');
const before = fs.readFileSync(record, 'utf8');
const validate = () => artifact(['validate', '--public', pub, '--private', path.join(out, 'run.json')]);
expect(validate().status).toBe(0);
const ownerWordsAt = (added: string) => { fs.writeFileSync(record, before + added); return validate().stderr.includes('ARTIFACT_OWNER_WORDS'); };
expect(ownerWordsAt(`The owner said “${ROWS[0]!.words}”.\n`)).toBe(true);
expect(ownerWordsAt(`The plan's reason: leave out: ${ROWS[2]!.reason}\n`)).toBe(true);
expect(ownerWordsAt(`A plain mention of ${ROWS[0]!.words} and ${ROWS[2]!.reason}.\n`)).toBe(false);
fs.writeFileSync(record, before);
expect(validate().status).toBe(0);
});
});
+31 -5
View File
@@ -26,6 +26,7 @@ const ONE_PAGE = fs.readFileSync(path.join(FIX, 'one-page-plan.md'), 'utf8');
const PLAY = JSON.parse(fs.readFileSync(path.join(FIX, 'play.json'), 'utf8'));
const COMMIT = 'c0ffee'.padEnd(40, '0');
const BUILD = { platform: 'ios' as const, commit: COMMIT, testflight: '17' };
const PHONE_BUILD = '01KPHQ7Z3M8V2X5C9B4N6R1T0W';
const HOLDING = { build: 'TestFlight build 16', defects: 'the care card shows yesterday as the last watered date' };
const T0 = new Date('2026-11-18T10:00:00Z');
const ACTIONS = [
@@ -44,7 +45,7 @@ const start = (o: { plan?: string; play?: unknown; root?: string; checker?: stri
const root = o.root ?? fresh('root'), work = fresh('work');
const planPath = path.join(work, 'plan.md');
fs.writeFileSync(planPath, o.plan ?? AUTOPLAN);
const r = startRun({ root, app: 'plantpal', planPath, build: BUILD, play: o.play ?? playWith(1), holding: HOLDING, builder: 'anthropic/claude-opus-5-5', checker: o.checker ?? CHECKER, now: T0 });
const r = startRun({ root, app: 'plantpal', planPath, build: BUILD, phoneBuild: PHONE_BUILD, play: o.play ?? playWith(1), holding: HOLDING, builder: 'anthropic/claude-opus-5-5', checker: o.checker ?? CHECKER, now: T0 });
if ('error' in r) throw new Error(r.error.detail);
return { ...r, planPath, work, root };
};
@@ -144,7 +145,7 @@ describe('model families and build fingerprints', () => {
test('a same-family or unknown checker refuses at start', () => {
const work = fresh('fam'), planPath = path.join(work, 'plan.md');
fs.writeFileSync(planPath, AUTOPLAN);
const base = { root: fresh('root'), app: 'plantpal', planPath, build: BUILD, play: PLAY, holding: HOLDING };
const base = { root: fresh('root'), app: 'plantpal', planPath, build: BUILD, phoneBuild: PHONE_BUILD, play: PLAY, holding: HOLDING };
expect(startRun({ ...base, builder: 'anthropic/claude-opus-5-5', checker: 'claude-fable-5-2' })).toMatchObject({ error: { code: 'FIRST_USE_SAME_FAMILY', detail: 'builder and checker are both anthropic' } });
expect(startRun({ ...base, builder: 'anthropic/claude-opus-5-5', checker: 'mystery-model' })).toMatchObject({ error: { code: 'FIRST_USE_SAME_FAMILY' } });
});
@@ -152,7 +153,7 @@ describe('model families and build fingerprints', () => {
test('the build the owner holds now is named at start: a label and its known defects, or none', () => {
const work = fresh('hold'), planPath = path.join(work, 'plan.md');
fs.writeFileSync(planPath, AUTOPLAN);
const base = { root: fresh('root'), app: 'plantpal', planPath, build: BUILD, play: PLAY, builder: 'anthropic/claude-opus-5-5', checker: CHECKER };
const base = { root: fresh('root'), app: 'plantpal', planPath, build: BUILD, phoneBuild: PHONE_BUILD, play: PLAY, builder: 'anthropic/claude-opus-5-5', checker: CHECKER };
expect(startRun({ ...base, holding: { build: 'TestFlight build 16' } })).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('--holding-defects') } });
expect('dir' in startRun({ ...base, holding: { build: 'none', defects: 'none' } })).toBe(true);
});
@@ -393,7 +394,7 @@ describe('the gate', () => {
expect(d.prediction?.score).toBe(6);
expect(d.owner).toMatchObject({ score: 5, words: '5, better after the fix' });
expect(fs.readdirSync(path.join(r.dir, 'owner'))).toHaveLength(2);
const again = startRun({ root: r.root, app: 'plantpal', planPath: r.planPath, build: BUILD, play: PLAY, holding: HOLDING, builder: 'anthropic/claude-opus-5-5', checker: CHECKER, now: T0 });
const again = startRun({ root: r.root, app: 'plantpal', planPath: r.planPath, build: BUILD, phoneBuild: PHONE_BUILD, play: PLAY, holding: HOLDING, builder: 'anthropic/claude-opus-5-5', checker: CHECKER, now: T0 });
expect(again).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID' } });
});
@@ -442,6 +443,31 @@ describe('the gate', () => {
expect(brief).not.toContain('TestFlight build 16');
});
test('a phone build installs the build-service build start names, and start refuses a phone build without one (GST-3646)', () => {
const work = fresh('phone'), planPath = path.join(work, 'plan.md');
fs.writeFileSync(planPath, AUTOPLAN);
const base = { app: 'plantpal', planPath, play: playWith(1), holding: HOLDING, builder: 'anthropic/claude-opus-5-5', checker: CHECKER, now: T0 };
for (const build of [BUILD, { platform: 'android' as const, commit: COMMIT, deploy: '1.0.3' }]) {
expect(startRun({ ...base, root: fresh('root'), build })).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('--phone-build') } });
expect(startRun({ ...base, root: fresh('root'), build, phoneBuild: '17' })).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('--phone-build') } });
}
const r = startRun({ ...base, root: fresh('root'), build: BUILD, phoneBuild: PHONE_BUILD });
if ('error' in r) throw new Error(r.error.detail);
expect(r.manifest.phone_build).toBe(PHONE_BUILD);
const brief = renderBrief(r.manifest, r.dir);
expect(brief).toContain(`(action "install" with build_id "${PHONE_BUILD}"`);
expect(brief).not.toContain('action "install"; TestFlight build');
const old = { ...r.manifest } as Partial<typeof r.manifest>;
delete old.phone_build;
fs.writeFileSync(path.join(r.dir, 'manifest.json'), JSON.stringify(old));
expect(readManifest(r.dir)).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('start a new run with --phone-build') } });
const android = startRun({ ...base, root: fresh('root'), build: { platform: 'android', commit: COMMIT, deploy: '1.0.3' }, phoneBuild: PHONE_BUILD });
if ('error' in android) throw new Error(android.error.detail);
expect(renderBrief(android.manifest, android.dir)).toContain(`build_id "${PHONE_BUILD}", the mobile build service's build of commit ${COMMIT.slice(0, 12)}, which version 1.0.3 ships`);
const web = startRun({ ...base, root: fresh('root'), build: { platform: 'web', commit: COMMIT, deploy: 'web-12' } });
expect('error' in web ? web.error.detail : web.manifest.phone_build).toBeUndefined();
});
test('the brief drives a Mac through Aside and a server over its shell', () => {
const work = fresh('mac'), planPath = path.join(work, 'plan.md');
fs.writeFileSync(planPath, AUTOPLAN);
@@ -485,7 +511,7 @@ describe('gstack-first-use (CLI, temporary HOME and drive)', () => {
const build = ['--platform', 'ios', '--commit', COMMIT, '--testflight', '17'];
const holding = ['--holding', 'TestFlight build 16', '--holding-defects', 'none'];
expect((await cli('start', '--app', 'plantpal', '--plan', plan, '--play', play, ...build, '--builder', 'anthropic/claude-opus-5-5', '--checker', CHECKER)).stderr).toContain('--holding, --holding-defects');
const begun = await cli('start', '--app', 'plantpal', '--plan', plan, '--play', play, ...build, ...holding, '--builder', 'anthropic/claude-opus-5-5', '--checker', CHECKER);
const begun = await cli('start', '--app', 'plantpal', '--plan', plan, '--play', play, ...build, '--phone-build', PHONE_BUILD, ...holding, '--builder', 'anthropic/claude-opus-5-5', '--checker', CHECKER);
expect(begun.code).toBe(0);
const dir = /^FIRST_USE_RUN: (.+)$/m.exec(begun.stdout)![1]!;
expect(dir.startsWith(path.join(home, '.capy', 'drive', 'user-ada-example', 'first-use', 'plantpal') + path.sep)).toBe(true);