Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions scripts/needs-you-canary/awaitAnswer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
CanaryOutcome as Outcome,
CanaryWeb
} from './canary.types';
import { surfaceAnswerers } from './canaryAsk';
import { homeAnswerer, surfaceAnswerers } from './canaryAsk';

const pollMs = 3000;
const appearMs = 120_000;
Expand All @@ -20,11 +20,14 @@ export function judgeAnswer(item: CanaryItem, ask: CanaryAsk): Outcome {
const label = ask.labels[ask.expected - 1];
const actor = surfaceAnswerers[ask.surface];
const read = `answered_by=${item.answered_by}, answer_option=${item.answer_option}`;
const right =
item.answered_by === actor &&
Number(item.answer_option) === ask.expected &&
item.answer === label;
if (right) return { state: 'passed', detail: `${read}, answered_at=${item.answered_at}` };
const right = Number(item.answer_option) === ask.expected && item.answer === label;
const timed = `${read}, answered_at=${item.answered_at}`;
if (right && item.answered_by === actor) return { state: 'passed', detail: timed };
if (right && item.answered_by === homeAnswerer) {
const why =
'Hub web and both app Home screens record this, so the record cannot name the device';
return { state: 'unconfirmed', detail: `right option, ${timed}; ${why}` };
}
return failed(`expected ${actor} and option ${ask.expected}, read ${read}`);
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/needs-you-canary/canary.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export interface CanaryOptions {
tapTimeoutMs?: number;
}

export type CanaryState = 'passed' | 'failed' | 'not-seen';
/** `unconfirmed`: the right answer arrived, but nothing shows which surface sent it. */
export type CanaryState = 'passed' | 'failed' | 'unconfirmed' | 'not-seen';

export interface CanaryResult {
surface: CanarySurface;
Expand Down
10 changes: 8 additions & 2 deletions scripts/needs-you-canary/canaryAsk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ export const surfaceNames: Record<CanarySurface, string> = {
};

/**
* What each app's own answer write records as `answered_by`: Hub web through the linked Mac, the Mac
* app's Needs you page (which names no one, as the CLI does too) and the iPhone's intent.
* What proves each surface as `answered_by`: Hub web through the linked Mac, the Mac app's Needs you
* page (which names no one, as the CLI does too) and the iPhone's intent.
*/
export const surfaceAnswerers: Record<CanarySurface, string> = {
web: 'Daniel via Hub',
mac: 'daniel',
iphone: 'Daniel'
};

/**
* The Home screens of the Mac and iPhone apps record the same as Hub web, because all three answer
* through the linked Mac. A right answer read this way is real but names no device.
*/
export const homeAnswerer = surfaceAnswerers.web;

const labels = ['Canary A', 'Canary B', 'Canary C'];
const effect = 'Test answer only. Nothing deploys or changes.';

Expand Down
3 changes: 2 additions & 1 deletion scripts/needs-you-canary/releaseAsk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function surfaceSummary(results: CanaryResult[]): string {
/** The flag words for a release that did not pass: what is unproven, and the ways forward. */
export function releaseAskArgs(release: string, results: CanaryResult[]): string[] {
const open = results.filter((result) => result.state !== 'passed');
const broken = open.some((result) => result.state === 'failed');
// Another tap cannot settle an unconfirmed surface, so only unseen ones recommend tapping.
const broken = open.some((result) => result.state !== 'not-seen');
const options = [tapAll, keepBlocked];
if (open.some((result) => result.detail === signedOut)) options.splice(1, 0, signInOnce);
const recommend = broken ? options.indexOf(keepBlocked) + 1 : 1;
Expand Down
13 changes: 9 additions & 4 deletions specification/features/planned/needs-you-release-canary.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ scripted check to run after it is deployed:
pressing that option on the "Blocked - needs you" row. A row without option buttons fails.
- A surface named in `--tap` is answered by Daniel by hand. This is the only way for the Mac app
and the iPhone.
- A surface passes only when the Tracker then reads back its own app's `answered_by`, with
- A surface passes only when the Tracker then reads back the `answered_by` that proves it, with
`answer_option` and `answer` equal to the named option, on an ask that was unanswered when the
surface was reached. `answered_by` is `Daniel via Hub` for Hub web, `daniel` for the Mac app and
`Daniel` for the iPhone. `test/needs-you-canary-answer-paths.test.ts` reads each from that app's
write code, so a change there fails the test.
surface was reached. That is `Daniel via Hub` for Hub web, `daniel` for the Mac app's Needs you
page and `Daniel` for the iPhone's replica intent. `test/needs-you-canary-answer-paths.test.ts`
reads each from that app's write code, so a change there fails the test.
- The Home screens of the Mac and iPhone apps answer through the linked Mac and also record
`Daniel via Hub`. A right option read that way on a Mac or iPhone ask is `unconfirmed`: it is not
a failed answer, and it does not pass, because a tap in Hub web or on the other device reads the
same. The release stays held. A wrong option or any other actor fails. Until answers record the
answering device (q84bd0), a person has to confirm which app sent an unconfirmed answer.
- `answered_by` names the write path, not the device or the person's hands. A Hub tap in a phone
browser reads as Hub web, and `daniel` is also what `tracker answer` writes without `--by`, so the
Mac result also rests on the instruction.
Expand Down
67 changes: 67 additions & 0 deletions specification/loops/q84bd0-canary-scoring/loop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "q84bd0-canary-scoring",
"goal": "Prove correct legacy app Home answers hold the release as unconfirmed",
"createdAt": "2026-11-30T15:52:59.740Z",
"updatedAt": "2026-11-30T15:56:36.358Z",
"template": "bug-fix",
"templateLineage": [
"bug-fix"
],
"enforceOrder": true,
"regressionCommits": 1,
"steps": [
{
"id": "spec",
"title": "Identify the failing behavior, expected behavior, and reproduction.",
"status": "complete",
"completedAt": "2026-11-30T15:53:19.646Z",
"evidence": "6kmyg7 run 1549 recorded the correct iPhone Home option under the shared Daniel via Hub actor; this must hold as unconfirmed"
},
{
"id": "coverage",
"title": "Explain why existing standardized tests missed the bug; name the scenario, fixture, lifecycle or assertion gap and reusable test change.",
"status": "complete",
"completedAt": "2026-11-30T15:53:22.405Z",
"evidence": "The existing canary answered from the replica intent and Mac inbox. It now exercises the app Home writer and checks wrong option, actor, and release disposition."
},
{
"id": "red",
"title": "Strengthen the existing standardized test; commit it before repair, run it failing with loop record --phase red, and preserve the assertion.",
"status": "complete",
"completedAt": "2026-11-30T15:54:44.185Z",
"evidence": "3efcec3440 failed three assertions; correct app Home answers scored failed instead of unconfirmed."
},
{
"id": "implement",
"title": "Implement the smallest repair without weakening the regression test.",
"status": "complete",
"completedAt": "2026-11-30T15:54:48.313Z",
"evidence": "c464d7804f preserves the release hold and wrong-option and wrong-actor failures."
},
{
"id": "green",
"title": "Rerun the same unchanged regression test at a separate fix commit with loop record --phase green; preserve passing proof.",
"status": "complete",
"completedAt": "2026-11-30T15:56:36.358Z",
"evidence": "Same two suites and unchanged regression passed in the clean snapshot at c464d7804f."
},
{
"id": "siblings",
"title": "Run harness loop siblings to record the root cause and evaluate the same pattern across committed source.",
"status": "pending"
},
{
"id": "verify",
"title": "Run relevant project checks and affected UI browser flows with fresh inspected screenshots and no unexpected browser errors; preserve diagnostics and keep pending until proof passes.",
"status": "pending"
}
],
"evaluators": [
{
"id": "check",
"title": "Run the project check script.",
"command": "bun run check",
"step": "verify"
}
]
}
6 changes: 6 additions & 0 deletions specification/loops/q84bd0-canary-scoring/trace.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"event":"loop.created","timestamp":"2026-11-30T15:52:59.740Z","name":"q84bd0-canary-scoring","goal":"Prove correct legacy app Home answers hold the release as unconfirmed","template":"bug-fix","templateLineage":["bug-fix"]}
{"event":"step.completed","timestamp":"2026-11-30T15:53:19.646Z","loop":"q84bd0-canary-scoring","step":"spec","evidence":"6kmyg7 run 1549 recorded the correct iPhone Home option under the shared Daniel via Hub actor; this must hold as unconfirmed"}
{"event":"step.completed","timestamp":"2026-11-30T15:53:22.405Z","loop":"q84bd0-canary-scoring","step":"coverage","evidence":"The existing canary answered from the replica intent and Mac inbox. It now exercises the app Home writer and checks wrong option, actor, and release disposition."}
{"event":"step.completed","timestamp":"2026-11-30T15:54:44.185Z","loop":"q84bd0-canary-scoring","step":"red","evidence":"3efcec3440 failed three assertions; correct app Home answers scored failed instead of unconfirmed."}
{"event":"step.completed","timestamp":"2026-11-30T15:54:48.313Z","loop":"q84bd0-canary-scoring","step":"implement","evidence":"c464d7804f preserves the release hold and wrong-option and wrong-actor failures."}
{"event":"step.completed","timestamp":"2026-11-30T15:56:36.358Z","loop":"q84bd0-canary-scoring","step":"green","evidence":"Same two suites and unchanged regression passed in the clean snapshot at c464d7804f."}
51 changes: 45 additions & 6 deletions test/needs-you-canary-answer-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { judgeAnswer } from '../scripts/needs-you-canary/awaitAnswer';
import type { CanarySurface } from '../scripts/needs-you-canary/canary.types';
import { canaryAsk } from '../scripts/needs-you-canary/canaryAsk';
import { canarySurfaces } from '../scripts/needs-you-canary/runCanary';
import { raise, realTracker, tapThrough, type RealTracker } from './support/needsYouCanaryClients';
import {
raise,
realTracker,
tapAppHome,
tapThrough,
type RealTracker
} from './support/needsYouCanaryClients';

let tracker: RealTracker;
beforeEach(() => void (tracker = realTracker()));
afterEach(() => tracker.close());

/** What the canary decides after `app` answers the ask it raised for `surface`. */
async function judged(surface: CanarySurface, app: CanarySurface) {
async function judged(surface: CanarySurface, app: CanarySurface, tap = tapThrough[app]) {
const ask = canaryAsk({
surface,
release: 'release-item',
Expand All @@ -19,7 +25,7 @@ async function judged(surface: CanarySurface, app: CanarySurface) {
byHand: true
});
const id = await raise(tracker, ask);
await tapThrough[app](tracker, id, ask, ask.expected);
await tap(tracker, id, ask, ask.expected);
const item = await tracker.read(`/items/${id}`);
expect(item).toMatchObject({ answer: 'Canary B', answer_option: 2 });
return { item, outcome: judgeAnswer(item, ask) };
Expand All @@ -35,8 +41,41 @@ describe('needs-you canary reads what each app really writes', () => {
canarySurfaces.filter((app) => app !== surface).map((app) => [surface, app] as const)
);

test.each(crossed)('fails a %s ask answered through the %s app', async (surface, app) => {
const { outcome } = await judged(surface, app);
expect(outcome).toMatchObject({ state: 'failed' });
// The Hub web path is the shared Home writer, which the app surfaces also use.
const shared = ([surface, app]: readonly [CanarySurface, CanarySurface]) =>
app === 'web' && surface !== 'web';

test.each(crossed.filter((pair) => !shared(pair)))(
'fails a %s ask answered through the %s app',
async (surface, app) => {
const { outcome } = await judged(surface, app);
expect(outcome).toMatchObject({ state: 'failed' });
}
);
});

describe('needs-you canary and the shared Home writer', () => {
test.each(['mac', 'iphone'] as const)(
'cannot confirm the device of a %s ask answered on an app Home screen',
async (surface) => {
const { item, outcome } = await judged(surface, surface, tapAppHome);
expect(item.answered_by).toBe('Daniel via Hub');
expect(outcome.state).toBe('unconfirmed');
expect(outcome.detail).toContain('cannot name the device');
}
);

test.each(['mac', 'iphone'] as const)('fails a wrong %s option there', async (surface) => {
const ask = canaryAsk({
surface,
release: 'release-item',
nonce: 'n1x',
expected: 2,
byHand: true
});
const id = await raise(tracker, ask);
await tapAppHome(tracker, id, ask, 3);
const item = await tracker.read(`/items/${id}`);
expect(judgeAnswer(item, ask).state).toBe('failed');
});
});
17 changes: 17 additions & 0 deletions test/needs-you-canary.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from 'vitest';
import { runCanary } from '../scripts/needs-you-canary/runCanary';
import { isTrackerCosMessage } from '../src/utils/projects-sessions/isTrackerPing';
import { trackerAskOptions } from '../src/utils/projects-sessions/trackerAskOptions';
import { canaryHub, canaryOptions, canaryTracker } from './support/needsYouCanaryWorld';
import type { CanaryWorld } from './support/needsYouCanaryWorld.types';

Expand Down Expand Up @@ -100,6 +101,22 @@ describe('needs-you release canary failures', () => {
expect(states(report)).toEqual({ web: 'passed', mac: 'failed', iphone: 'failed' });
expect(report.passed).toBe(false);
});

test('holds the release on right answers that name no device', async () => {
const { world, release, item } = setup();
const report = await runCanary(
canaryOptions(world, { release, taps: everyHand }, (question) => {
const marker = /\[canary-[a-z0-9-]+\]/.exec(question)![0];
world.tap(marker, 'Canary B', 'Daniel via Hub');
})
);
expect(states(report)).toEqual({ web: 'passed', mac: 'unconfirmed', iphone: 'unconfirmed' });
expect(report.passed).toBe(false);
expect(item().status).toBe('blocked');
expect(item().blocked_reason).toBe('needs-you canary: mac unconfirmed, iphone unconfirmed');
const choices = trackerAskOptions(item().options as string);
expect(choices.find((choice) => choice.recommended)?.label).toBe('Keep the release blocked');
});
});

describe('needs-you release canary holds and cleanup', () => {
Expand Down
32 changes: 32 additions & 0 deletions test/support/needsYouCanaryClients.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { DatabaseSync } from 'node:sqlite';
import { vi } from 'vitest';
import { MacTrackerInboxService } from '../../packages/desktop/src/lib/development-tooling/desktop-initialization/MacTrackerInboxService';
import { createHomeChatWriter } from '../../packages/desktop/src/lib/development-tooling/desktop-initialization/tracker-overview-publisher/createHomeChatWriter';
import { deliverHomeChat } from '../../packages/desktop/src/lib/development-tooling/desktop-initialization/tracker-overview-publisher/homeTrackerChat';
import { optionWrite } from '../../packages/desktop/src/lib/development-tooling/tracker-inbox/trackerInbox';
import type { InboxDetail } from '../../packages/desktop/src/models/development-tooling/TrackerInbox.types';
import { agentOpenAsks } from '../../packages/reports/src/lib/projects-sessions/hub-home/homeOpenAsks';
import type { HomeAgent } from '../../packages/reports/src/lib/projects-sessions/hub-home/hubHome.types';
import {
buildHomeSnapshot,
noProviders
} from '../../packages/reports/src/lib/projects-sessions/hub-home/homeTrackerProjection';
import { readTrackerSources } from '../../packages/reports/src/lib/projects-sessions/project-overview/projectOverviewTracker';
import type {
CanaryAsk,
CanaryItem,
Expand Down Expand Up @@ -122,6 +128,32 @@ async function tapIphone(tracker: RealTracker, id: string, ask: CanaryAsk, optio
accepted('iPhone', receipt.status === 'accepted', receipt.status);
}

/**
* The Home screen of the installed Mac app (local bridge) and iPhone app (relayed to that Mac):
* both hand the tap to the one writer `initializeDesktop` builds with `createHomeChatWriter`.
*/
export async function tapAppHome(tracker: RealTracker, id: string, ask: CanaryAsk, option: number) {
// The daemon serves runs and machines elsewhere; items and the write stay on the real store.
const send = (async (url: string, init?: RequestInit) =>
['/runs', '/machines'].includes(new URL(url).pathname)
? Response.json([])
: tracker.send(url, init)) as typeof fetch;
const sources = await readTrackerSources(send, true);
const listed = buildHomeSnapshot(sources, noProviders, Date.now()).openAsks?.find(
(entry) => entry.itemId === id
);
const receipt = await createHomeChatWriter(send)({
id: '00000000-0000-4000-8000-000000000002',
agentId: listed?.agentId,
itemId: id,
question: ask.question,
kind: 'answer',
text: ask.labels[option - 1],
option
});
accepted('App Home', receipt.status === 'sent', receipt.status);
}

export const tapThrough: Record<
CanarySurface,
(tracker: RealTracker, id: string, ask: CanaryAsk, option: number) => Promise<void>
Expand Down
Loading