Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

refactor: drop the unused core-search backend injection point

Joshua France3768b9e6f4bd
diff --git a/src/api/app-search.ts b/src/api/app-search.ts
index 114054df1..dde41d6c5 100644
--- a/src/api/app-search.ts
+++ b/src/api/app-search.ts
@@ -112,12 +112,9 @@ function slackBackend(deps: AppDeps, app: App): SearchBackend | null {
}
export function createSearchMethods(deps: AppDeps, app: App): Pick<App, "search"> {
const slack = slackBackend(deps, app);
- const core = createCoreSearch(
- [conversationBackend(app), ...(slack ? [slack] : []), fileBackend(app), ...(deps.searchBackends ?? [])],
- {
- onBackendError: (backend, error) =>
- console.error(`[search] backend ${backend} failed:`, error instanceof Error ? error.message : String(error)),
- },
- );
+ const core = createCoreSearch([conversationBackend(app), ...(slack ? [slack] : []), fileBackend(app)], {
+ onBackendError: (backend, error) =>
+ console.error(`[search] backend ${backend} failed:`, error instanceof Error ? error.message : String(error)),
+ });
return { search: (query, principals, limit) => core.search({ query, principals, limit }) };
}
diff --git a/src/api/app-types.ts b/src/api/app-types.ts
index d722b0176..81afcaffb 100644
--- a/src/api/app-types.ts
+++ b/src/api/app-types.ts
@@ -97,7 +97,7 @@ import type { ModelProviderAvailability } from "../model/pi-models.ts";
import type { RuntimeChoice } from "../harness/harness-router.ts";
import { type ReachOpts, type ReachResolution, type ReachTarget } from "../reach/reach.ts";
import { type Project, type ProjectStore } from "../projects/project-store.ts";
-import type { SearchBackend, SearchHit } from "../search/core-search.ts";
+import type { SearchHit } from "../search/core-search.ts";
interface DeploymentVersionView {
version: number;
@@ -571,7 +571,6 @@ export interface AppDeps {
modelProviders?: ModelProviderAvailability;
providerKeys?: ModelProviderAvailability;
runtimeFallback?: RuntimeChoice;
- searchBackends?: readonly SearchBackend[];
}
export interface ContextSummary {
diff --git a/src/wiring.ts b/src/wiring.ts
index ed9827936..d0fa40155 100644
--- a/src/wiring.ts
+++ b/src/wiring.ts
@@ -294,7 +294,6 @@ import { createPostgresMetricsSink } from "./admin/postgres-metrics-sink.ts";
import { errMessage, swallowAs } from "./util/errors.ts";
import { sleep } from "./util/async.ts";
import { createSlackInstallationStore, type SlackInstallationStore } from "./surfaces/slack-installation.ts";
-import type { SearchBackend } from "./search/core-search.ts";
export interface Runtime {
start(): void;
@@ -404,7 +403,6 @@ export function buildApp(
securityScreener?: SecurityScreener;
credentialBrokers?: Record<string, AwsRoleBroker>;
modelCredentialFetch?: typeof fetch;
- searchBackends?: readonly SearchBackend[];
} = {},
): BuiltApp {
if (config.databaseUrl && !config.connectorSecretKey) {
@@ -1316,7 +1314,6 @@ export function buildApp(
providerKeys,
modelProviders: modelProviderAvailabilityFor(config.harness, providerKeys),
runWaitMs: config.runWaitMs,
- ...(overrides.searchBackends ? { searchBackends: overrides.searchBackends } : {}),
});
const slackCore = createSlackCoreClient({
app,
diff --git a/test/core-search.test.ts b/test/core-search.test.ts
index 0f2cb5e20..869bbf830 100644
--- a/test/core-search.test.ts
+++ b/test/core-search.test.ts
@@ -56,22 +56,22 @@ test("intersection backend requires visibility to every principal", async () =>
);
});
test("POST /v1/search derives principals from capability and shared scopes fail closed", async () => {
- const seen: string[][] = [];
- const external: SearchBackend = {
- name: "external",
- async search(r) {
- seen.push(r.principals.map((p) => p.id));
- return [];
- },
- };
const secret = "search-route-secret".repeat(3);
- const built = buildApp(testConfig({ dataDir: mkdtempSync(join(tmpdir(), "search-")), signingSecret: secret }), {
- searchBackends: [external],
- });
+ const built = buildApp(testConfig({ dataDir: mkdtempSync(join(tmpdir(), "search-")), signingSecret: secret }));
await built.directory.replaceChannels(
- [{ channelId: "C1", name: "private", isPrivate: true }],
- principals.map((p) => ({ channelId: "C1", principalId: p.id })),
+ [
+ { channelId: "C1", name: "private", isPrivate: true },
+ { channelId: "C-ALICE", name: "alice-only", isPrivate: true },
+ ],
+ [
+ ...principals.map((p) => ({ channelId: "C1", principalId: p.id })),
+ { channelId: "C-ALICE", principalId: principals[0]!.id },
+ ],
);
+ await built.app.ingestSurfaceEvents([
+ { container: "C1", ts: "1", text: "pelican launch shared", kind: "channel" },
+ { container: "C-ALICE", ts: "2", text: "pelican launch private", kind: "channel" },
+ ]);
const server = createServer(built.app, { signingSecret: secret, auditLog: built.auditLog });
await new Promise<void>((r) => server.listen(0, "127.0.0.1", r));
const base = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
@@ -89,16 +89,26 @@ test("POST /v1/search derives principals from capability and shared scopes fail
fetch(`${base}/v1/search`, {
method: "POST",
headers: { "content-type": "application/json", "x-agent-capability": cap },
- body: JSON.stringify({ query: "plan" }),
+ body: JSON.stringify({ query: "pelican" }),
});
try {
- assert.equal((await post(await token(principals))).status, 200);
- assert.deepEqual(seen, [["[email protected]", "[email protected]"]]);
- assert.equal((await post(await token())).status, 409);
- assert.equal(seen.length, 1);
- const event = (await built.auditLog.events()).find((e) => e.action === "search.query");
- assert.ok(event);
- assert.doesNotMatch(event.detail ?? "", /plan/);
+ const ok = await post(await token(principals));
+ assert.equal(ok.status, 200);
+ const body = (await ok.json()) as { hits: Array<{ id: string; backend: string }> };
+ assert.deepEqual(
+ body.hits.filter((hit) => hit.backend === "slack").map((hit) => hit.id),
+ ["C1:1"],
+ "a message only one participant can see is never returned to the shared conversation",
+ );
+
+ const missing = await post(await token());
+ assert.equal(missing.status, 409);
+ assert.equal(((await missing.json()) as { error: string }).error, "principal_set_unavailable");
+
+ const events = (await built.auditLog.events()).filter((e) => e.action === "search.query");
+ assert.equal(events.length, 1, "a fail-closed request runs no search and records none");
+ assert.match(events[0]!.detail ?? "", /"principals":\["[email protected]","[email protected]"\]/);
+ assert.doesNotMatch(events[0]!.detail ?? "", /pelican/, "query text is not copied into the audit log");
} finally {
await new Promise<void>((r) => server.close(() => r()));
}