@@ -198,54 +198,62 @@ it.each([
198198 );
199199});
200200
201- it("keeps a pasted thread the agent can't read as a link to its machine", async () => {
202- const target = DraftId.make("clipboard-threads");
203- const store = useComposerDraftStore.getState();
204- using _draft = { [Symbol.dispose]: () => store.clearComposerContent(target) };
205- const thread = (environmentId: string, threadId: string) => ({
206- version: 1 as const,
207- kind: "thread" as const,
208- contextId: ComposerContextId.make(`thread_${threadId}`),
209- label: `Thread ${threadId}`,
210- environmentId: EnvironmentId.make(environmentId),
211- threadId: ThreadId.make(threadId),
212- title: `Thread ${threadId}`,
213- });
214- const unlinked = thread("unlinked-source", "remote");
215- const linked = thread("linked-source", "linked");
216- let importer!: Importer;
217- await using _screen = await render(
218- <Harness
219- input={{
220- environmentId: EnvironmentId.make("clipboard-target"),
221- linkedEnvironments: new Map([[linked.environmentId, "Linked"]]),
222- activeThread: undefined,
223- activeThreadId: null,
224- composerDraftTarget: target,
225- attachmentDraftTarget: target,
226- attachmentTargetKey: target,
227- attachmentTargetKeyRef: { current: target },
228- questionAttachmentTarget: null,
229- pendingUserInputs: [],
230- composerContextRecords: new Map(),
231- composerImages: [],
232- composerFilesRef: { current: [] },
233- pendingThreadImportsRef: { current: new Map() },
234- promptRef: { current: "" },
235- addComposerFilesToDraft: (files) => store.addFiles(target, files),
236- }}
237- ready={(value) => {
238- importer = value;
239- }}
240- />,
241- );
242- let remapped!: ReturnType<Importer["importContextRecords"]>;
243- await act(async () => {
244- remapped = importer.importContextRecords([unlinked, linked], unlinked.environmentId);
245- });
246- expect(Object.fromEntries(remapped)).toEqual({
247- [unlinked.contextId]: { markdown: "[Thread remote](t3-thread://v2/unlinked-source/remote)" },
248- [linked.contextId]: linked.contextId,
249- });
250- expect(store.getComposerDraft(target)?.threadContexts).toEqual([linked]);
251- });
201+ it.each([false, true])(
202+ "keeps an unreadable thread as a link (already attached: %s)",
203+ async (alreadyAttached) => {
204+ const target = DraftId.make("clipboard-threads");
205+ const store = useComposerDraftStore.getState();
206+ using _draft = { [Symbol.dispose]: () => store.clearComposerContent(target) };
207+ const thread = (environmentId: string, threadId: string) => ({
208+ version: 1 as const,
209+ kind: "thread" as const,
210+ contextId: ComposerContextId.make(`thread_${threadId}`),
211+ label: `Thread ${threadId}`,
212+ environmentId: EnvironmentId.make(environmentId),
213+ threadId: ThreadId.make(threadId),
214+ title: `Thread ${threadId}`,
215+ });
216+ const unlinked = thread("unlinked-source", "remote");
217+ const linked = thread("linked-source", "linked");
218+ if (alreadyAttached) store.addThreadContexts(target, [unlinked], { appendReference: false });
219+ let importer!: Importer;
220+ await using _screen = await render(
221+ <Harness
222+ input={{
223+ environmentId: EnvironmentId.make("clipboard-target"),
224+ linkedEnvironments: new Map([[linked.environmentId, "Linked"]]),
225+ activeThread: undefined,
226+ activeThreadId: null,
227+ composerDraftTarget: target,
228+ attachmentDraftTarget: target,
229+ attachmentTargetKey: target,
230+ attachmentTargetKeyRef: { current: target },
231+ questionAttachmentTarget: null,
232+ pendingUserInputs: [],
233+ composerContextRecords: new Map(
234+ alreadyAttached ? [[unlinked.contextId, { kind: "thread", record: unlinked }]] : [],
235+ ),
236+ composerImages: [],
237+ composerFilesRef: { current: [] },
238+ pendingThreadImportsRef: { current: new Map() },
239+ promptRef: { current: "" },
240+ addComposerFilesToDraft: (files) => store.addFiles(target, files),
241+ }}
242+ ready={(value) => {
243+ importer = value;
244+ }}
245+ />,
246+ );
247+ let remapped!: ReturnType<Importer["importContextRecords"]>;
248+ await act(async () => {
249+ remapped = importer.importContextRecords([unlinked, linked], unlinked.environmentId);
250+ });
251+ expect(Object.fromEntries(remapped)).toEqual({
252+ [unlinked.contextId]: { markdown: "[Thread remote](t3-thread://v2/unlinked-source/remote)" },
253+ [linked.contextId]: linked.contextId,
254+ });
255+ expect(store.getComposerDraft(target)?.threadContexts).toEqual(
256+ alreadyAttached ? [unlinked, linked] : [linked],
257+ );
258+ },
259+ );
0 commit comments