Skip to content
Closed
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
64 changes: 64 additions & 0 deletions apps/web/src/components/settings/SettingsPanels.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {
DEFAULT_SERVER_SETTINGS,
EnvironmentId,
ProviderDriverKind,
ProviderInstanceId,
ThreadId,
type ProviderInstanceConfig,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import {
archivedThreadSelectionKey,
buildArchivedThreadSelectionKeys,
buildProviderInstanceUpdatePatch,
pruneArchivedThreadSelection,
formatDiagnosticsDescription,
} from "./SettingsPanels.logic";

Expand Down Expand Up @@ -102,3 +107,62 @@ describe("buildProviderInstanceUpdatePatch", () => {
expect(patch.providers).toBeUndefined();
});
});

describe("archived thread selection helpers", () => {
it("scopes selection keys by environment and thread", () => {
const threadId = ThreadId.make("thread-1");

expect(
archivedThreadSelectionKey({
environmentId: EnvironmentId.make("environment-a"),
threadId,
}),
).toBe("environment-a:thread-1");
expect(
archivedThreadSelectionKey({
environmentId: EnvironmentId.make("environment-b"),
threadId,
}),
).toBe("environment-b:thread-1");
});

it("keeps duplicate thread ids distinct across environments", () => {
const threadId = ThreadId.make("thread-1");
const selected = new Set([
archivedThreadSelectionKey({
environmentId: EnvironmentId.make("environment-a"),
threadId,
}),
archivedThreadSelectionKey({
environmentId: EnvironmentId.make("environment-b"),
threadId,
}),
]);

expect(selected.size).toBe(2);
});

it("builds select-all keys from scoped archived threads", () => {
expect(
buildArchivedThreadSelectionKeys([
{
environmentId: EnvironmentId.make("environment-a"),
threadId: ThreadId.make("thread-1"),
},
{
environmentId: EnvironmentId.make("environment-b"),
threadId: ThreadId.make("thread-1"),
},
]),
).toEqual(["environment-a:thread-1", "environment-b:thread-1"]);
});

it("prunes selections that are no longer present in archived snapshots", () => {
const selected = new Set(["environment-a:thread-1", "environment-a:thread-2"]);
const available = new Set(["environment-a:thread-2", "environment-b:thread-1"]);

expect([...pruneArchivedThreadSelection(selected, available)]).toEqual([
"environment-a:thread-2",
]);
});
});
31 changes: 31 additions & 0 deletions apps/web/src/components/settings/SettingsPanels.logic.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
import type {
EnvironmentId,
ProviderDriverKind,
ProviderInstanceConfig,
ProviderInstanceId,
ServerSettings,
ThreadId,
UnifiedSettings,
} from "@t3tools/contracts";
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";

export type ArchivedThreadSelectionItem = {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
};

export function archivedThreadSelectionKey(input: ArchivedThreadSelectionItem): string {
return scopedThreadKey(scopeThreadRef(input.environmentId, input.threadId));
}

export function buildArchivedThreadSelectionKeys(
threads: ReadonlyArray<ArchivedThreadSelectionItem>,
): ReadonlyArray<string> {
return threads.map(archivedThreadSelectionKey);
}

export function pruneArchivedThreadSelection(
selectedKeys: ReadonlySet<string>,
availableKeys: ReadonlySet<string>,
): Set<string> {
const next = new Set<string>();
for (const key of selectedKeys) {
if (availableKeys.has(key)) {
next.add(key);
}
}
return next;
}

function collapseOtelSignalsUrl(input: {
readonly tracesUrl: string;
readonly metricsUrl: string;
Expand Down
Loading
Loading