Files
t3code/apps/server/src/persistence/Layers/ProjectionRepositories.test.ts
T
Theo BrowneandClaude Fable 5 5dfc78e85e Add sidebar v2 beta: flat adaptive-density thread list with settled lifecycle
A new thread sidebar behind a Settings → Beta toggle (sidebarV2Enabled,
default off). One flat recency-sorted list across projects: active threads
render as two-line cards (favicon, title, time, status word · branch ·
provider glyph + model · machine), settled threads collapse to slim
one-liners. Approval-blocked threads pin to the top with wait time; failed
sessions (session.lastError) finally get a visible state.

Settled is an event-sourced lifecycle state mirroring the archived pattern:
- settledOverride ("settled" | "active" | null) + settledAt on the thread,
  thread.settle/thread.unsettle commands, thread.settled/thread.unsettled
  events, projection columns via migration 033.
- effectiveSettled() computes the visible state: manual override beats
  auto rules (PR merged/closed, N days of inactivity — client setting,
  default 3, nullable). Idempotency is by event re-emission since the
  engine rejects zero-event commands.
- Activity auto-unsettles server-side: turn start, live session start,
  approval/user-input requests. Session stop/error status writes do not.

Manually settling a thread whose worktree is orphaned offers a one-click
worktree removal (re-validated at click time, never forced).

The v2 component is a sibling swapped at the single AppSidebarLayout mount
point; shared chrome moved to sidebar/SidebarChrome.tsx. The data model is
flag-independent and ships dark for v1 users, so toggling is a pure view
swap.

Plan: .plans/21-sidebar-v2-beta.md

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-15 02:30:32 -07:00

134 lines
4.5 KiB
TypeScript

import { ProjectId, ThreadId, ProviderInstanceId } from "@t3tools/contracts";
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as SqlClient from "effect/unstable/sql/SqlClient";
import { SqlitePersistenceMemory } from "./Sqlite.ts";
import { ProjectionProjectRepositoryLive } from "./ProjectionProjects.ts";
import { ProjectionThreadRepositoryLive } from "./ProjectionThreads.ts";
import { ProjectionProjectRepository } from "../Services/ProjectionProjects.ts";
import { ProjectionThreadRepository } from "../Services/ProjectionThreads.ts";
const projectionRepositoriesLayer = it.layer(
Layer.mergeAll(
ProjectionProjectRepositoryLive.pipe(Layer.provideMerge(SqlitePersistenceMemory)),
ProjectionThreadRepositoryLive.pipe(Layer.provideMerge(SqlitePersistenceMemory)),
SqlitePersistenceMemory,
),
);
projectionRepositoriesLayer("Projection repositories", (it) => {
it.effect("stores SQL NULL for missing project model options", () =>
Effect.gen(function* () {
const projects = yield* ProjectionProjectRepository;
const sql = yield* SqlClient.SqlClient;
yield* projects.upsert({
projectId: ProjectId.make("project-null-options"),
title: "Null options project",
workspaceRoot: "/tmp/project-null-options",
defaultModelSelection: {
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-5.4",
},
scripts: [],
createdAt: "2026-03-24T00:00:00.000Z",
updatedAt: "2026-03-24T00:00:00.000Z",
deletedAt: null,
});
const rows = yield* sql<{
readonly defaultModelSelection: string | null;
}>`
SELECT default_model_selection_json AS "defaultModelSelection"
FROM projection_projects
WHERE project_id = 'project-null-options'
`;
const row = rows[0];
if (!row) {
return yield* Effect.die("Expected projection_projects row to exist.");
}
assert.strictEqual(
row.defaultModelSelection,
// @effect-diagnostics-next-line preferSchemaOverJson:off
JSON.stringify({
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-5.4",
}),
);
const persisted = yield* projects.getById({
projectId: ProjectId.make("project-null-options"),
});
assert.deepStrictEqual(Option.getOrNull(persisted)?.defaultModelSelection, {
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-5.4",
});
}),
);
it.effect("stores JSON for thread model options", () =>
Effect.gen(function* () {
const threads = yield* ProjectionThreadRepository;
const sql = yield* SqlClient.SqlClient;
yield* threads.upsert({
threadId: ThreadId.make("thread-null-options"),
projectId: ProjectId.make("project-null-options"),
title: "Null options thread",
modelSelection: {
instanceId: ProviderInstanceId.make("claudeAgent"),
model: "claude-opus-4-6",
},
runtimeMode: "full-access",
interactionMode: "default",
branch: null,
worktreePath: null,
latestTurnId: null,
createdAt: "2026-03-24T00:00:00.000Z",
updatedAt: "2026-03-24T00:00:00.000Z",
archivedAt: null,
settledOverride: null,
settledAt: null,
latestUserMessageAt: null,
pendingApprovalCount: 0,
pendingUserInputCount: 0,
hasActionableProposedPlan: 0,
deletedAt: null,
});
const rows = yield* sql<{
readonly modelSelection: string | null;
}>`
SELECT model_selection_json AS "modelSelection"
FROM projection_threads
WHERE thread_id = 'thread-null-options'
`;
const row = rows[0];
if (!row) {
return yield* Effect.die("Expected projection_threads row to exist.");
}
assert.strictEqual(
row.modelSelection,
// @effect-diagnostics-next-line preferSchemaOverJson:off
JSON.stringify({
instanceId: ProviderInstanceId.make("claudeAgent"),
model: "claude-opus-4-6",
}),
);
const persisted = yield* threads.getById({
threadId: ThreadId.make("thread-null-options"),
});
assert.deepStrictEqual(Option.getOrNull(persisted)?.modelSelection, {
instanceId: ProviderInstanceId.make("claudeAgent"),
model: "claude-opus-4-6",
});
}),
);
});