Q176: onboarding progress survives a restart, and an unfinished setup reopens

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-09 05:25:01 -04:00
1 parent 43dcb1e7d3
commit fd79f059ca
20 files changed
+341 -71

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
import { _electron as electron, expect, test } from "@playwright/test";
import { mkdirSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { randomUUID } from "node:crypto";
import { seedBuiltinSkillsFixture } from "./builtin-skills-fixture";
test("onboarding resumes where it was left after the app is closed", async () => {
const profileDir = join(tmpdir(), `agentcompany-new-e2e-resume-${randomUUID()}`);
mkdirSync(profileDir, { recursive: true });
const builtinDir = seedBuiltinSkillsFixture(join(tmpdir(), `agentcompany-new-e2e-resume-builtin-${randomUUID()}`));
const launch = () => electron.launch({
args: [resolve("out/main/index.js")],
env: { ...process.env, AGENTCOMPANY_NEW_PROFILE_DIR: profileDir, AGENTCOMPANY_NEW_AUTORUN: "0", AGENTCOMPANY_NEW_BUILTIN_SKILLS_DIR: builtinDir },
});
// Fill the first steps, then close the app mid-wizard.
let app = await launch();
let page = await app.firstWindow();
await page.getByRole("button", { name: "Get started" }).click();
await page.getByLabel("API key").fill("e2e-secret");
await page.getByLabel("Model").fill("gpt-5.4");
await page.getByRole("button", { name: "Continue" }).click();
await page.getByLabel("Company name").fill("Resume Co");
await page.getByLabel("Your name").fill("Dana Lee");
await page.getByLabel("Description").fill("Survives a restart.");
await page.getByRole("button", { name: "Continue" }).click();
await expect(page.getByRole("heading", { name: "Mode" })).toBeVisible();
await expect.poll(() => page.evaluate(async () => {
const api = (window as unknown as { agentCompany: { loadSnapshot: () => Promise<{ ok: true; data: { onboardingDraft: { step: string; companyName: string } | null } }> } }).agentCompany;
const draft = (await api.loadSnapshot()).data.onboardingDraft;
return draft && `${draft.step}:${draft.companyName}`;
})).toBe("mode:Resume Co");
await app.close();
// The wizard comes back on the same step with what was typed; the key is not kept.
app = await launch();
page = await app.firstWindow();
await expect(page.getByRole("heading", { name: "Mode" })).toBeVisible();
await expect(page.getByRole("status").filter({ hasText: "Your progress was restored." })).toBeVisible();
await page.getByRole("button", { name: "Back" }).click();
await expect(page.getByLabel("Company name")).toHaveValue("Resume Co");
await page.getByRole("button", { name: "Back" }).click();
await expect(page.getByLabel("API key")).toHaveValue("");
await page.getByLabel("API key").fill("e2e-secret");
await page.getByLabel("Model").fill("gpt-5.4");
await page.getByRole("button", { name: "Continue" }).click();
await page.getByRole("button", { name: "Continue" }).click();
await page.getByRole("button", { name: "Continue" }).click();
await page.getByLabel("Goal").fill("Ship it.");
await page.getByLabel("Acceptance criteria").fill("It ships.");
await page.getByRole("button", { name: "Launch" }).click();
await expect(page.getByRole("heading", { name: "Connectors" })).toBeVisible();
await app.close();
// A company whose setup was not finished reopens on the connectors step, then enters the app.
app = await launch();
page = await app.firstWindow();
await expect(page.getByRole("heading", { name: "Connectors" })).toBeVisible();
await page.getByRole("button", { name: "Finish" }).click();
await expect(page.getByRole("button", { name: "Settings" })).toBeVisible();
// A cancelled second company leaves nothing behind for the next attempt.
const savedModel = () => page.evaluate(async () => {
const api = (window as unknown as { agentCompany: { loadSnapshot: () => Promise<{ ok: true; data: { onboardingDraft: { providerModel: string } | null } }> } }).agentCompany;
return (await api.loadSnapshot()).data.onboardingDraft?.providerModel ?? null;
});
await page.getByRole("button", { name: "Resume Co — switch organization" }).click();
await page.getByRole("menuitem", { name: "New organization" }).click();
await page.getByRole("button", { name: "Get started" }).click();
await page.getByLabel("API key").fill("e2e-secret");
await page.getByLabel("Model").fill("cancelled-model");
await expect.poll(savedModel).toBe("cancelled-model");
// Saving a preference refreshes the in-memory snapshot, which now holds the draft too.
await page.getByRole("button", { name: "Back", exact: true }).click();
await page.getByRole("button", { name: "中文" }).click();
await page.getByRole("button", { name: "English" }).click();
// Past the 800 ms change-event reload window, so only Cancel itself can refresh the snapshot.
await page.waitForTimeout(1_200);
await page.getByRole("button", { name: "Cancel" }).click();
await expect(page.getByRole("button", { name: "Settings" })).toBeVisible();
expect(await savedModel()).toBeNull();
await page.getByRole("button", { name: "Resume Co — switch organization" }).click();
await page.getByRole("menuitem", { name: "New organization" }).click();
await expect(page.getByRole("status").filter({ hasText: "Your progress was restored." })).toHaveCount(0);
await page.getByRole("button", { name: "Get started" }).click();
await page.getByLabel("API key").fill("e2e-secret");
await expect(page.getByLabel("Model")).not.toHaveValue("cancelled-model");
await page.getByRole("button", { name: "Cancel" }).click();
await app.close();
app = await launch();
page = await app.firstWindow();
await expect(page.getByRole("button", { name: "Settings" })).toBeVisible();
await expect(page.getByRole("heading", { name: "Connectors" })).toHaveCount(0);
await app.close();
});
+1 -1
View File
@@ -35,7 +35,7 @@ describe("domain services", () => {
const connection = createConnection();
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104]);
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105]);
connection.close();
});
+59
View File
@@ -0,0 +1,59 @@
import { randomUUID } from "node:crypto";
import { DatabaseSync } from "node:sqlite";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
import { DatabaseConnection } from "../../src/main/database/connection";
import { OnboardingService } from "../../src/main/services/onboarding-service";
import { ProviderService } from "../../src/main/services/provider-service";
import { providerAdapters } from "../../src/main/services/provider-adapters";
import { completeSetup, loadOnboardingDraft, saveOnboardingDraft } from "../../src/main/services/onboarding-progress";
import { onboardingProgressSchema } from "../../src/main/database/migrations/105-onboarding-progress";
import type { OnboardingDraft } from "../../src/shared/commands";
const vault = { encryptSecret: (secret: string) => Buffer.from(secret, "utf8"), decryptSecret: (ciphertext: Buffer) => ciphertext.toString("utf8") };
const draft: OnboardingDraft = {
step: "mode", companyName: "Resume Co", companyDescription: "d", employeeName: "Dana", workspacePath: "", executionMode: "ai_ceo",
providerKey: "openai", providerBaseUrl: "", providerModel: "gpt-5.4", goalTitle: "", goalDescription: "",
};
describe("onboarding progress", () => {
test("the wizard is kept until launch, and a launched company stays unfinished until its setup is done", () => {
const connection = new DatabaseConnection(join(tmpdir(), `ac-onboarding-progress-${randomUUID()}.db`));
const db = connection.db;
expect(loadOnboardingDraft(db)).toBeNull();
saveOnboardingDraft(db, draft);
expect(loadOnboardingDraft(db)).toEqual(draft);
const providers = new ProviderService(db, providerAdapters, vault);
const onboarding = new OnboardingService({ db, saveProviderCredential: (input) => providers.saveCredential(input) });
let orgId = "";
connection.transaction(() => {
orgId = onboarding.bootstrap({
companyName: "Resume Co", companyDescription: "d", employeeName: "Dana", workspacePath: "", executionMode: "ai_ceo", autoApproveHires: true,
reviewDeliverables: false, goalTitle: "Ship.", goalDescription: "d", providerKey: "openai", providerSecret: "sk-test", providerModel: "gpt-5.4",
}).orgId;
});
expect(loadOnboardingDraft(db)).toBeNull();
expect(db.prepare("select setup_completed_at from organizations where id = ?").get(orgId)).toEqual({ setup_completed_at: null });
completeSetup(db, orgId);
const done = (db.prepare("select setup_completed_at from organizations where id = ?").get(orgId) as { setup_completed_at: string }).setup_completed_at;
expect(done).not.toBeNull();
completeSetup(db, orgId);
expect(db.prepare("select setup_completed_at from organizations where id = ?").get(orgId)).toEqual({ setup_completed_at: done });
expect(() => completeSetup(db, "org_missing")).toThrow("Organization was not found.");
});
test("companies that existed before count as set up", () => {
const db = new DatabaseSync(":memory:");
db.exec(`
create table schema_migrations(version integer, name text, applied_at text);
create table app_state(id integer primary key, updated_at text);
create table organizations(id text primary key, created_at text);
insert into organizations(id, created_at) values ('org_a', '2026-01-01T00:00:00.000Z');
`);
db.exec(onboardingProgressSchema);
expect(db.prepare("select setup_completed_at from organizations").get()).toEqual({ setup_completed_at: "2026-01-01T00:00:00.000Z" });
});
});