+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
202 lines
7.1 KiB
TypeScript
202 lines
7.1 KiB
TypeScript
import { assert, it } from "@effect/vitest";
|
|
import {
|
|
EventId,
|
|
MessageId,
|
|
ProjectId,
|
|
ProviderInstanceId,
|
|
ThreadId,
|
|
type OrchestrationV2DomainEvent,
|
|
} from "@t3tools/contracts";
|
|
import * as DateTime from "effect/DateTime";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Layer from "effect/Layer";
|
|
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
|
|
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
|
|
import * as ProjectionStore from "./ProjectionStore.ts";
|
|
import * as ProjectStore from "./ProjectStore.ts";
|
|
import * as ThreadSearch from "./ThreadSearch.ts";
|
|
|
|
const TestLayer = Layer.mergeAll(
|
|
ThreadSearch.layer,
|
|
ProjectionStore.layer,
|
|
ProjectStore.layer,
|
|
).pipe(Layer.provideMerge(SqlitePersistenceMemory));
|
|
|
|
const providerInstanceId = ProviderInstanceId.make("codex");
|
|
const at = (minute: number) => DateTime.makeUnsafe(Date.UTC(2026, 8, 27, 0, minute));
|
|
|
|
const createProject = (projectId: ProjectId) =>
|
|
Effect.flatMap(ProjectStore.ProjectStoreV2, (projects) =>
|
|
projects.apply({
|
|
sequence: 0,
|
|
eventId: EventId.make(`created:${projectId}`),
|
|
aggregateKind: "project",
|
|
aggregateId: projectId,
|
|
occurredAt: DateTime.formatIso(at(0)),
|
|
commandId: null,
|
|
causationEventId: null,
|
|
correlationId: null,
|
|
metadata: {},
|
|
type: "project.created",
|
|
payload: {
|
|
projectId,
|
|
title: projectId,
|
|
workspaceRoot: `/work/${projectId}`,
|
|
defaultModelSelection: null,
|
|
scripts: [],
|
|
createdAt: DateTime.formatIso(at(0)),
|
|
updatedAt: DateTime.formatIso(at(0)),
|
|
},
|
|
}),
|
|
);
|
|
|
|
const thread = (
|
|
threadId: ThreadId,
|
|
projectId: ProjectId,
|
|
overrides: { readonly archivedAt?: DateTime.Utc; readonly deletedAt?: DateTime.Utc } = {},
|
|
): OrchestrationV2DomainEvent => ({
|
|
id: EventId.make(`created:${threadId}`),
|
|
type: "thread.created",
|
|
threadId,
|
|
providerInstanceId,
|
|
occurredAt: at(0),
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: threadId,
|
|
projectId,
|
|
title: threadId,
|
|
providerInstanceId,
|
|
modelSelection: { instanceId: providerInstanceId, model: "gpt-5" },
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
activeProviderThreadId: null,
|
|
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
|
|
forkedFrom: null,
|
|
createdAt: at(0),
|
|
updatedAt: at(0),
|
|
archivedAt: overrides.archivedAt ?? null,
|
|
settledOverride: null,
|
|
settledAt: null,
|
|
lastVisitedAt: null,
|
|
deletedAt: overrides.deletedAt ?? null,
|
|
},
|
|
});
|
|
|
|
const message = (
|
|
threadId: ThreadId,
|
|
id: string,
|
|
role: "user" | "assistant" | "system",
|
|
text: string,
|
|
options: { readonly minute?: number; readonly streaming?: boolean } = {},
|
|
): OrchestrationV2DomainEvent => ({
|
|
id: EventId.make(`message:${id}`),
|
|
type: "message.updated",
|
|
threadId,
|
|
providerInstanceId,
|
|
occurredAt: at(options.minute ?? 1),
|
|
payload: {
|
|
createdBy: role === "user" ? "user" : "agent",
|
|
creationSource: role === "user" ? "web" : "provider",
|
|
id: MessageId.make(id),
|
|
threadId,
|
|
runId: null,
|
|
nodeId: null,
|
|
role,
|
|
text,
|
|
attachments: [],
|
|
streaming: options.streaming ?? false,
|
|
createdAt: at(options.minute ?? 1),
|
|
updatedAt: at(options.minute ?? 1),
|
|
},
|
|
});
|
|
|
|
it.layer(TestLayer)("ThreadSearch", (it) => {
|
|
it.effect("returns one finished user or assistant match per active thread", () =>
|
|
Effect.gen(function* () {
|
|
const projections = yield* ProjectionStore.ProjectionStoreV2;
|
|
const search = yield* ThreadSearch.ThreadSearch;
|
|
const project = ProjectId.make("project:search");
|
|
const deletedProject = ProjectId.make("project:search-deleted");
|
|
yield* createProject(project);
|
|
yield* createProject(deletedProject);
|
|
yield* Effect.flatMap(ProjectStore.ProjectStoreV2, (projects) =>
|
|
projects.apply({
|
|
sequence: 0,
|
|
eventId: EventId.make("deleted:project"),
|
|
aggregateKind: "project",
|
|
aggregateId: deletedProject,
|
|
occurredAt: DateTime.formatIso(at(2)),
|
|
commandId: null,
|
|
causationEventId: null,
|
|
correlationId: null,
|
|
metadata: {},
|
|
type: "project.deleted",
|
|
payload: { projectId: deletedProject, deletedAt: DateTime.formatIso(at(2)) },
|
|
}),
|
|
);
|
|
|
|
const both = ThreadId.make("thread:both");
|
|
const assistantOnly = ThreadId.make("thread:assistant");
|
|
const events: ReadonlyArray<OrchestrationV2DomainEvent> = [
|
|
thread(both, project),
|
|
message(both, "both-assistant", "assistant", "needle from the answer", { minute: 3 }),
|
|
message(both, "both-user-old", "user", "older needle question", { minute: 1 }),
|
|
message(both, "both-user-new", "user", "newer needle question", { minute: 2 }),
|
|
thread(assistantOnly, project),
|
|
message(assistantOnly, "assistant-only", "assistant", "needle in an answer"),
|
|
message(assistantOnly, "assistant-streaming", "user", "needle still typing", {
|
|
streaming: true,
|
|
}),
|
|
message(assistantOnly, "assistant-system", "system", "needle system prompt"),
|
|
thread(ThreadId.make("thread:archived"), project, { archivedAt: at(1) }),
|
|
message(ThreadId.make("thread:archived"), "archived", "user", "needle archived"),
|
|
thread(ThreadId.make("thread:deleted"), project, { deletedAt: at(1) }),
|
|
message(ThreadId.make("thread:deleted"), "deleted", "user", "needle deleted"),
|
|
thread(ThreadId.make("thread:orphaned"), deletedProject),
|
|
message(ThreadId.make("thread:orphaned"), "orphaned", "user", "needle orphaned"),
|
|
];
|
|
yield* Effect.forEach(events, projections.apply, { discard: true });
|
|
|
|
const result = yield* search.search({ query: "NEEDLE", limit: 20 });
|
|
assert.deepEqual(
|
|
result.matches.map((match) => [match.threadId, match.source, match.snippet]),
|
|
[
|
|
[both, "user", "newer needle question"],
|
|
[assistantOnly, "assistant", "needle in an answer"],
|
|
],
|
|
);
|
|
assert.lengthOf((yield* search.search({ query: "needle", limit: 1 })).matches, 1);
|
|
// LIKE wildcards in the query match literally.
|
|
assert.deepEqual((yield* search.search({ query: "ne%le" })).matches, []);
|
|
}),
|
|
);
|
|
|
|
it.effect("reports an unreadable match as a decode failure", () =>
|
|
Effect.gen(function* () {
|
|
const projections = yield* ProjectionStore.ProjectionStoreV2;
|
|
const search = yield* ThreadSearch.ThreadSearch;
|
|
const sql = yield* SqlClient.SqlClient;
|
|
const project = ProjectId.make("project:search-corrupt");
|
|
const threadId = ThreadId.make("thread:corrupt");
|
|
yield* createProject(project);
|
|
yield* Effect.forEach(
|
|
[thread(threadId, project), message(threadId, "corrupt", "user", "20260927")],
|
|
projections.apply,
|
|
{ discard: true },
|
|
);
|
|
yield* sql`
|
|
UPDATE orchestration_v2_projection_messages
|
|
SET payload_json = json_set(payload_json, '$.text', 20260927)
|
|
WHERE message_id = 'corrupt'
|
|
`;
|
|
|
|
const error = yield* Effect.flip(search.search({ query: "0260927" }));
|
|
assert.equal(error.operation, "decode");
|
|
}),
|
|
);
|
|
});
|