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
36 changes: 36 additions & 0 deletions apps/server/src/project/AgentSessionImporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ function candidate(
}

const PI_MODEL_SELECTION = { instanceId: ProviderInstanceId.make("pi"), model: "default" };
const OPENCODE_MODEL_SELECTION = {
instanceId: ProviderInstanceId.make("opencode"),
model: "zai-coding-plan/glm-5.4",
};

// Pi threads are owned by their session file path, not the session UUID.
const nativeId = ({ source }: ReturnType<typeof candidate>) =>
Expand Down Expand Up @@ -456,6 +460,32 @@ it.effect("rechecks ownership after the import reaches the commit transaction",
}).pipe(Effect.scoped, Effect.provide(persistence)),
);

// An imported OpenCode thread continues the OpenCode session it was read from.
it.effect("binds an imported OpenCode thread to its OpenCode session", () =>
Effect.gen(function* () {
const projections = yield* ProjectionStore.ProjectionStoreV2;
const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
const source = candidate(OPENCODE_MODEL_SELECTION, "ses_opencode", "opencode");
const threadId = importId(source);
const importer = yield* makeImporter([source]);
expect(yield* importer.run).toEqual({ importedCount: 1, skippedCount: 0 });
const records = yield* projections.getThreadRecords(threadId, ["providerThreads"]);
expect(records.thread).toMatchObject({
providerInstanceId: "opencode",
modelSelection: { instanceId: "opencode", model: "zai-coding-plan/glm-5.4" },
});
expect(records.providerThreads[0]).toMatchObject({
driver: "opencode",
nativeThreadRef: { driver: "opencode", nativeId: "ses_opencode", strength: "strong" },
});
expect(Option.getOrThrow(yield* runtimes.getByThreadId({ threadId }))).toMatchObject({
providerName: "opencode",
adapterKey: "opencode",
resumeCursor: { threadId: "ses_opencode" },
});
}).pipe(Effect.scoped, Effect.provide(persistence)),
);

it.effect(
"retries failed commits and runtime persistence without replaying committed history",
() =>
Expand Down Expand Up @@ -1025,6 +1055,12 @@ it.effect("repeated imports reach linked-worktree sessions behind the scan budge
enabled: false,
config: {},
},
// Keeps the default OpenCode instance off the developer's real OpenCode history.
[ProviderInstanceId.make("opencode")]: {
driver: ProviderDriverKind.make("opencode"),
enabled: false,
config: {},
},
},
}),
Layer.mock(ProjectStore.ProjectStoreV2)({ listShells: () => Effect.succeed([]) }),
Expand Down
Loading
Loading