Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/scripts/arc-ci-coverage.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const REQUIRED_TESTS = [
"apps/server/src/orchestration-v2/ModelAlertReactor.test.ts",
"apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts",
"apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts",
"apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts",
"packages/shared/src/threadPlacement.test.ts",
"apps/server/src/peer/RemoteDelegation.test.ts",
"apps/server/src/mcp/OrchestratorMcpService.test.ts",
Expand Down
8 changes: 8 additions & 0 deletions .github/scripts/arc-ci-coverage.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ test("a covering step with any step-level if: fails the check", () => {
);
}
});

test("compaction delivery integration suite is required by the coverage guard (CLO-1096)", () => {
const suite = "apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts";
assert.ok(REQUIRED_TESTS.includes(suite));
const dropped = workflow.replace(` ${suite} \\\n`, "");
assert.notEqual(dropped, workflow);
assert.ok(checkCoverage(dropped).some((problem) => problem.includes(suite)));
});
5 changes: 5 additions & 0 deletions .github/workflows/closura-arc-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ jobs:
'packages/client-runtime/src/state/threadListFilter.ts': ['matchesPrimaryInbox', 'matchesListedInboxes', 'hiddenEnvironmentIds'],
'apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx': ['Kameron', 'Jeff', 'Agents', 'Environments'],
'apps/web/src/components/sidebar/threadListFilter.logic.ts': ['matchesListedInboxes', 'hiddenEnvironmentIds'],
'apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts': [
'promoting %s into a compaction stops it and sends it next',
'settles a steered completion wake whose parent run is before the last compaction (restart by intent: %s)',
],
};
for (const [file, needles] of Object.entries(required)) {
const source = readFileSync(file, 'utf8');
Expand Down Expand Up @@ -221,6 +225,7 @@ jobs:
apps/server/src/orchestration-v2/ModelAlertReactor.test.ts \
apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts \
apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts \
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts \
packages/shared/src/threadPlacement.test.ts \
apps/server/src/peer/RemoteDelegation.test.ts \
apps/server/src/mcp/OrchestratorMcpService.test.ts \
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/app/DesktopAppIdentity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe("DesktopAppIdentity", () => {
const identity = yield* DesktopAppIdentity.DesktopAppIdentity;
const userDataPath = yield* identity.resolveUserDataPath;

assert.equal(userDataPath, "/Users/alice/Library/Application Support/t3code-v2");
assert.equal(userDataPath, "/Users/alice/Library/Application Support/closura-t3code-v2");
}),
{ legacyPathExists: true },
),
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/app/DesktopClerk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ describe("DesktopClerk", () => {
name: "packaged macOS",
isDevelopment: false,
platform: "darwin" as const,
userData: "/tmp/app-data/t3code-v2",
userData: "/tmp/app-data/closura-t3code-v2",
},
{
name: "packaged Linux",
isDevelopment: false,
platform: "linux" as const,
userData: "/tmp/app-data/t3code-v2",
userData: "/tmp/app-data/closura-t3code-v2",
},
{
name: "packaged Windows",
isDevelopment: false,
platform: "win32" as const,
userData: "/tmp/app-data/t3code-v2",
userData: "/tmp/app-data/closura-t3code-v2",
},
{
name: "development",
Expand Down Expand Up @@ -300,7 +300,7 @@ describe("DesktopClerk", () => {

assert.isTrue(Exit.hasInterrupts(exit));
assert.deepEqual(events, [
"setPath:userData:/tmp/app-data/t3code-v2",
"setPath:userData:/tmp/app-data/closura-t3code-v2",
"requestSingleInstanceLock",
"quit",
]);
Expand Down
105 changes: 103 additions & 2 deletions apps/desktop/src/app/DesktopUserData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,108 @@ import * as FileSystem from "effect/FileSystem";
import * as Path from "effect/Path";
import * as PlatformError from "effect/PlatformError";

import { clearStaleGpuCaches, resolveUserDataPath } from "./DesktopUserData.ts";
import {
CLOSURA_FORK_USER_DATA_DIR,
clearStaleGpuCaches,
resolveUserDataPath,
} from "./DesktopUserData.ts";

it.effect.each(["linux", "darwin", "win32"] as const)(
"uses a distinct Closura fork user-data directory on %s and migrates existing t3code-v2 state once (CLO-1100)",
(platform) =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-closura-profile-" });
const stockDir = path.join(directory, "t3code-v2");
const forkDir = path.join(directory, CLOSURA_FORK_USER_DATA_DIR);

yield* fs.makeDirectory(path.join(stockDir, "Local Storage"), { recursive: true });
yield* fs.makeDirectory(path.join(stockDir, "GPUCache"), { recursive: true });
yield* fs.writeFileString(path.join(stockDir, "Preferences"), '{"fork":true}');
yield* fs.writeFileString(path.join(stockDir, "Local Storage", "data"), "saved-state");
yield* fs.writeFileString(path.join(stockDir, "Local Storage", "LOCK"), "locked");
yield* fs.writeFileString(path.join(stockDir, "SingletonLock"), "pid");
yield* fs.writeFileString(path.join(stockDir, "GPUCache", "data_0"), "stale-gpu");

const firstPath = yield* resolveUserDataPath({
appDataDirectory: directory,
isDevelopment: false,
platform,
});
assert.equal(firstPath, forkDir);
assert.notEqual(firstPath, stockDir);
assert.equal(yield* fs.readFileString(path.join(forkDir, "Preferences")), '{"fork":true}');
assert.equal(
yield* fs.readFileString(path.join(forkDir, "Local Storage", "data")),
"saved-state",
);
assert.isFalse(yield* fs.exists(path.join(forkDir, "SingletonLock")));
assert.isFalse(yield* fs.exists(path.join(forkDir, "Local Storage", "LOCK")));
assert.isFalse(yield* fs.exists(path.join(forkDir, "GPUCache")));
assert.isTrue(yield* fs.exists(path.join(forkDir, ".migrated-from-t3code-v2")));
// Stock profile remains intact for side-by-side stock T3 Code installs.
assert.equal(yield* fs.readFileString(path.join(stockDir, "Preferences")), '{"fork":true}');

// Subsequent launches must not overwrite fork state even if stock profile changes.
yield* fs.writeFileString(path.join(forkDir, "Preferences"), '{"fork":"updated"}');
yield* fs.writeFileString(path.join(stockDir, "Preferences"), '{"stock":"mutated"}');
const secondPath = yield* resolveUserDataPath({
appDataDirectory: directory,
isDevelopment: false,
platform,
});
assert.equal(secondPath, forkDir);
assert.equal(
yield* fs.readFileString(path.join(forkDir, "Preferences")),
'{"fork":"updated"}',
);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect(
"redoes an interrupted t3code-v2 migration instead of keeping a partial fork profile (CLO-1100)",
() =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-closura-partial-" });
const stockDir = path.join(directory, "t3code-v2");
const forkDir = path.join(directory, CLOSURA_FORK_USER_DATA_DIR);
const stagingDir = `${forkDir}.migrating`;
yield* fs.makeDirectory(path.join(stockDir, "IndexedDB"), { recursive: true });
yield* fs.writeFileString(path.join(stockDir, "Preferences"), "prefs");
yield* fs.writeFileString(path.join(stockDir, "IndexedDB", "db"), "indexed");
yield* fs.writeFileString(path.join(stockDir, "Cookies"), "cookies");

// A copy that failed partway leaves only its staging directory behind.
yield* fs.makeDirectory(stagingDir, { recursive: true });
yield* fs.writeFileString(path.join(stagingDir, "Preferences"), "prefs");
const cookies = path.join(stockDir, "Cookies");
yield* fs.chmod(cookies, 0o000);
const failure = yield* Effect.flip(
resolveUserDataPath({
appDataDirectory: directory,
isDevelopment: false,
platform: "linux",
}),
);
assert.equal(failure._tag, "DesktopUserDataInitializationError");
assert.isFalse(yield* fs.exists(forkDir));

yield* fs.chmod(cookies, 0o644);
const resolved = yield* resolveUserDataPath({
appDataDirectory: directory,
isDevelopment: false,
platform: "linux",
});
assert.equal(resolved, forkDir);
assert.isFalse(yield* fs.exists(stagingDir));
assert.equal(yield* fs.readFileString(path.join(forkDir, "IndexedDB", "db")), "indexed");
assert.equal(yield* fs.readFileString(path.join(forkDir, "Cookies")), "cookies");
assert.isTrue(yield* fs.exists(path.join(forkDir, ".migrated-from-t3code-v2")));
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect.each(["t3code", "T3 Code (Alpha)"])(
"preserves Windows credential keys from %s without copying browser databases",
Expand All @@ -15,7 +116,7 @@ it.effect.each(["t3code", "T3 Code (Alpha)"])(
const path = yield* Path.Path;
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-v2-profile-" });
const source = path.join(directory, sourceName);
const destination = path.join(directory, "t3code-v2");
const destination = path.join(directory, CLOSURA_FORK_USER_DATA_DIR);
const state = '{"os_crypt":{"encrypted_key":"test-encrypted-key"}}';
yield* fs.makeDirectory(path.join(directory, "T3 Code (Alpha)"), { recursive: true });
yield* fs.makeDirectory(path.join(source, "IndexedDB"), { recursive: true });
Expand Down
105 changes: 103 additions & 2 deletions apps/desktop/src/app/DesktopUserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import * as Schema from "effect/Schema";
export class DesktopUserDataInitializationError extends Schema.TaggedError<DesktopUserDataInitializationError>()(
"DesktopUserDataInitializationError",
{
operation: Schema.Literals(["inspect", "read", "create-directory", "write"]),
operation: Schema.Literals([
"inspect",
"read",
"create-directory",
"write",
"remove",
"rename",
]),
resourcePath: Schema.String,
category: Schema.String,
cause: Schema.Defect(),
Expand All @@ -31,6 +38,67 @@ export class DesktopUserDataInitializationError extends Schema.TaggedError<Deskt
}
}

export const CLOSURA_FORK_USER_DATA_DIR = "closura-t3code-v2";
const STOCK_V2_USER_DATA_DIR = "t3code-v2";
const MIGRATION_MARKER_FILE = ".migrated-from-t3code-v2";
const MIGRATION_SKIP_NAMES = new Set([
"SingletonLock",
"SingletonCookie",
"SingletonSocket",
"LOCK",
"GPUCache",
"GrShaderCache",
"ShaderCache",
"DawnGraphiteCache",
"DawnWebGPUCache",
"GPUPersistentCache",
]);

const copyProfileTree = Effect.fn("desktop.userData.copyProfileTree")(function* (
fs: FileSystem.FileSystem,
path: Path.Path,
sourceDir: string,
targetDir: string,
): Effect.fn.Return<void, DesktopUserDataInitializationError> {
yield* fs
.makeDirectory(targetDir, { recursive: true })
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "create-directory", targetDir),
),
);
const entries = yield* fs
.readDirectory(sourceDir)
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "read", sourceDir),
),
);
for (const name of entries) {
if (MIGRATION_SKIP_NAMES.has(name)) continue;
const src = path.join(sourceDir, name);
const dst = path.join(targetDir, name);
const info = yield* fs
.stat(src)
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "inspect", src),
),
);
if (info.type === "Directory") {
yield* copyProfileTree(fs, path, src, dst);
} else if (info.type === "File") {
yield* fs
.copyFile(src, dst)
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "write", dst),
),
);
}
}
});

export const resolveUserDataPath = Effect.fn("desktop.userData.resolveUserDataPath")(
function* (input: {
readonly appDataDirectory: string;
Expand All @@ -41,7 +109,7 @@ export const resolveUserDataPath = Effect.fn("desktop.userData.resolveUserDataPa
const path = yield* Path.Path;
const names = input.isDevelopment
? { current: "t3code-dev", legacy: "T3 Code (Dev)" }
: { current: "t3code-v2", legacy: "T3 Code (Alpha)" };
: { current: CLOSURA_FORK_USER_DATA_DIR, legacy: "T3 Code (Alpha)" };
const destinationPath = path.join(input.appDataDirectory, names.current);
const legacyPath = path.join(input.appDataDirectory, names.legacy);
const inspect = (resourcePath: string) =>
Expand All @@ -55,6 +123,39 @@ export const resolveUserDataPath = Effect.fn("desktop.userData.resolveUserDataPa
if (input.isDevelopment) {
return (yield* inspect(legacyPath)) ? legacyPath : destinationPath;
}
// Isolate the Closura fork profile from stock `t3code-v2` so side-by-side installs
// never corrupt each other. If the fork profile does not exist yet and a prior
// `t3code-v2` profile is present, copy it once and leave `t3code-v2` untouched.
const stockV2Path = path.join(input.appDataDirectory, STOCK_V2_USER_DATA_DIR);
if (!(yield* inspect(destinationPath)) && (yield* inspect(stockV2Path))) {
// Stage the copy and rename it into place so an interrupted migration never
// leaves a partial fork profile that later launches would treat as complete.
const stagingPath = `${destinationPath}.migrating`;
yield* fs
.remove(stagingPath, { recursive: true, force: true })
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "remove", stagingPath),
),
);
yield* copyProfileTree(fs, path, stockV2Path, stagingPath);
const markerPath = path.join(stagingPath, MIGRATION_MARKER_FILE);
yield* fs
.writeFileString(markerPath, "migrated\n")
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "write", markerPath),
),
);
yield* fs
.rename(stagingPath, destinationPath)
.pipe(
Effect.mapError((cause) =>
DesktopUserDataInitializationError.fromFileSystem(cause, "rename", destinationPath),
),
);
return destinationPath;
}
// Chromium databases require their own profile for each running version.
if (input.platform !== "win32") return destinationPath;
const destinationState = path.join(destinationPath, "Local State");
Expand Down
Loading
Loading