Skip to content

Commit c824877

Browse files
t3dotggclaude
andcommitted
test(triage): cover the open-draft seed and the parent-repo clone check
Both tests fail on the code before their fixes. Mobile also reports a failed "Copy command" instead of dropping it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ae37e3f commit c824877

3 files changed

Lines changed: 50 additions & 16 deletions

File tree

‎apps/mobile/src/features/triage/useStartTriage.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ export function useStartTriage() {
3636
"Could not start triage",
3737
`${message} Run ${CLI_COMMAND} in a terminal on that machine instead.`,
3838
[
39-
{ text: "Copy command", onPress: () => void Clipboard.setStringAsync(CLI_COMMAND) },
39+
{
40+
text: "Copy command",
41+
onPress: () =>
42+
void Clipboard.setStringAsync(CLI_COMMAND).catch(() =>
43+
Dialog.alert("Could not copy", `Type ${CLI_COMMAND} instead.`),
44+
),
45+
},
4046
{ text: "OK", style: "cancel" },
4147
],
4248
);

‎apps/server/src/triage/TriageService.test.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,17 @@ it.effect("still starts triage when the source lookup fails", () =>
146146
}).pipe(Effect.provide(TestLayer)),
147147
);
148148

149-
it.effect("does not trust a folder that is not a checkout of the commit", () =>
149+
it.effect("does not trust a folder without its own .git, even inside a repo at that commit", () =>
150150
Effect.gen(function* () {
151151
const fs = yield* FileSystem.FileSystem;
152152
const config = yield* ServerConfig.ServerConfig;
153153
yield* fs.makeDirectory(`${config.baseDir}/source/${RELEASE_COMMIT}`, { recursive: true });
154-
const { triage } = yield* makeTriage((command) =>
155-
command === "ls-remote"
156-
? Effect.succeed(`${RELEASE_COMMIT}\trefs/tags/v${packageJson.version}\n`)
157-
: Effect.fail(
158-
new GitCommandError({
159-
operation: "TriageService.checkSource",
160-
command: "git rev-parse",
161-
cwd: "/",
162-
detail: "not a git repository",
163-
}),
164-
),
165-
);
154+
// The stub answers rev-parse with the commit, as a parent repository could.
155+
const { triage, commands } = yield* makeTriage();
166156

167157
yield* triage.prepare({ client: {} });
168158

159+
assert.notInclude(commands, "rev-parse");
169160
assert.include(yield* readContext, "is not a complete checkout");
170161
}).pipe(Effect.provide(TestLayer)),
171162
);

‎apps/web/src/hooks/useHandleNewThread.test.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const testState = vi.hoisted(() => {
1818
readonly promotedTo: null;
1919
readonly threadId: string;
2020
} | null = null;
21+
let openDraftRoute: { readonly kind: "draft"; readonly draftId: string } | null = null;
2122
const router = {
2223
state: {
2324
location: { href: "/" },
@@ -30,7 +31,18 @@ const testState = vi.hoisted(() => {
3031
const draftStore = {
3132
getComposerDraft: vi.fn(() => ({})),
3233
getDraftSessionByLogicalProjectKey: vi.fn(() => storedDraft),
33-
getDraftSession: vi.fn(() => null),
34+
getDraftSession: vi.fn(() =>
35+
openDraftRoute === null
36+
? null
37+
: {
38+
logicalProjectKey: "remote-project",
39+
promotedTo: null,
40+
threadId: "thread-open",
41+
createdAt: "2026-01-01T00:00:00.000Z",
42+
runtimeMode: "full-access",
43+
interactionMode: "default",
44+
},
45+
),
3446
getDraftThread: vi.fn(() => null),
3547
applyStickyState: vi.fn(),
3648
setDraftThreadContext: vi.fn(),
@@ -57,6 +69,12 @@ const testState = vi.hoisted(() => {
5769
removeProject() {
5870
projectRemoved = true;
5971
},
72+
get openDraftRoute() {
73+
return openDraftRoute;
74+
},
75+
openEmptyDraft(draftId: string) {
76+
openDraftRoute = { kind: "draft", draftId };
77+
},
6078
get targetSettings() {
6179
return targetSettings;
6280
},
@@ -68,6 +86,7 @@ const testState = vi.hoisted(() => {
6886
},
6987
) {
7088
storedDraft = nextStoredDraft;
89+
openDraftRoute = null;
7190
projectRemoved = false;
7291
connectedEnvironmentIds = ["environment-primary", "environment-ssh"];
7392
targetSettings = {
@@ -210,7 +229,9 @@ vi.mock("../state/server", () => ({
210229
environmentServerConfigsAtom: {},
211230
primaryServerSettingsAtom: "primary-settings",
212231
}));
213-
vi.mock("../threadRoutes", () => ({ resolveThreadRouteTarget: () => null }));
232+
vi.mock("../threadRoutes", () => ({
233+
resolveThreadRouteTarget: () => testState.openDraftRoute,
234+
}));
214235
vi.mock("../uiStateStore", () => ({
215236
legacyProjectCwdPreferenceKey: () => "remote-project",
216237
useUiStateStore: () => [],
@@ -284,6 +305,22 @@ describe.each([
284305
});
285306

286307
describe("useNewThreadHandler", () => {
308+
it("seeds the prompt into the empty draft that is already open", async () => {
309+
testState.reset(null);
310+
testState.openEmptyDraft("draft-open");
311+
312+
const opened = await useNewThreadHandler()(
313+
{ environmentId: "environment-ssh", projectId: "project-remote" } as never,
314+
{ prompt: "Read the playbook. " },
315+
);
316+
317+
expect(opened?.draftId).toBe("draft-open");
318+
expect(testState.draftStore.setPrompt).toHaveBeenCalledWith(
319+
"draft-open",
320+
"Read the playbook. ",
321+
);
322+
});
323+
287324
it("opens the draft without waiting on a project file from an offline machine", async () => {
288325
testState.reset(null, { envMode: null, startFromOrigin: false });
289326
testState.disconnect("environment-ssh");

0 commit comments

Comments
 (0)