mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
71918c6575
Add pi.dev account integration, profile setup, shared session support, activity sync, and slash command support using shared pi.dev OAuth/client utilities.
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import {
|
|
getPendingSetupStepIds,
|
|
hasPendingSetupSteps,
|
|
markSetupStepComplete,
|
|
readSetupState,
|
|
} from "../src/core/setup-state.ts";
|
|
|
|
const tempDirs: string[] = [];
|
|
|
|
function createTempDir(): string {
|
|
const dir = mkdtempSync(join(tmpdir(), "pi-setup-state-"));
|
|
tempDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const dir of tempDirs.splice(0)) {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
describe("setup state", () => {
|
|
it("prompts new users for theme before pi.dev profiles", () => {
|
|
const agentDir = createTempDir();
|
|
|
|
expect(getPendingSetupStepIds(agentDir)).toEqual(["theme", "pi-dev-profile"]);
|
|
});
|
|
|
|
it("skips the theme setup step when a theme is already configured", () => {
|
|
const agentDir = createTempDir();
|
|
|
|
expect(getPendingSetupStepIds(agentDir, { themeConfigured: true })).toEqual(["pi-dev-profile"]);
|
|
});
|
|
|
|
it("prompts existing setup users for theme and pi.dev profile steps", () => {
|
|
const agentDir = createTempDir();
|
|
writeFileSync(
|
|
join(agentDir, "setup.json"),
|
|
JSON.stringify({
|
|
schemaVersion: 1,
|
|
completedVersion: 1,
|
|
steps: {
|
|
telemetry: { completedAt: "2026-01-01T00:00:00.000Z", setupVersion: 1 },
|
|
login: { completedAt: "2026-01-01T00:00:00.000Z", setupVersion: 1 },
|
|
},
|
|
}),
|
|
);
|
|
|
|
expect(getPendingSetupStepIds(agentDir)).toEqual(["theme", "pi-dev-profile"]);
|
|
|
|
markSetupStepComplete("theme", agentDir, new Date("2026-01-02T00:00:00.000Z"));
|
|
markSetupStepComplete("pi-dev-profile", agentDir, new Date("2026-01-02T00:00:00.000Z"));
|
|
|
|
expect(hasPendingSetupSteps(agentDir)).toBe(false);
|
|
expect(readSetupState(agentDir)?.completedVersion).toBe(1);
|
|
});
|
|
});
|