Skip to content
Merged
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
14 changes: 9 additions & 5 deletions packages/app/src/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ export class TenantV2 extends DurableObject<Env> {
return Promise.all(rows.map(async row => ({ ...(JSON.parse(await decrypt(String(row.value), this.env.CREDENTIAL_ENCRYPTION_KEY)) as any), integrationId: String(row.kind).slice(16) })));
}

private async tailIntegrationStatus(): Promise<Array<Record<string, unknown>>> {
const installations = await this.tailIntegrations();
return installations.map(({ signingSecret: _secret, ...installation }) => ({ ...installation, status: "connected", secretConfigured: true,
referencedJobCount: Number((this.one("SELECT count(DISTINCT job_id) AS count FROM triggers WHERE kind='webhook' AND json_extract(config,'$.provider')='cloudflareTail' AND json_extract(config,'$.integrationId')=?", installation.integrationId) as Row)?.count ?? 0) }));
private async tailIntegrationStatus(installations?: Array<{ integrationId: string; name: string; signingSecret: string; createdAt: string; updatedAt: string }>): Promise<Array<Record<string, unknown>>> {
const loadedInstallations = installations ?? await this.tailIntegrations();
const referencedJobCounts = new Map(this.rows(
"SELECT json_extract(config,'$.integrationId') AS integration_id, count(DISTINCT job_id) AS count FROM triggers WHERE kind='webhook' AND json_extract(config,'$.provider')='cloudflareTail' GROUP BY json_extract(config,'$.integrationId')",
).map(row => [String(row.integration_id), Number(row.count ?? 0)] as const));
return loadedInstallations.map(({ signingSecret: _secret, ...installation }) => ({ ...installation, status: "connected", secretConfigured: true,
referencedJobCount: referencedJobCounts.get(installation.integrationId) ?? 0 }));
}

private async saveTailIntegration(input: unknown): Promise<Response> {
Expand Down Expand Up @@ -454,13 +457,14 @@ export class TenantV2 extends DurableObject<Env> {
const connections = await this.exeConnections();
const exe = await this.connection<ExeConnectionInput>("exe");
const ampConnections = await this.ampConnections();
const tailInstallations = await this.tailIntegrations();
return json({
linear: linear ? { organizationName: linear.organizationName ?? null, viewerEmail: linear.viewerEmail ?? null } : null,
clickup: clickup ? { teamName: clickup.teamName ?? null } : null,
exe: exe ? { vmName: exe.vmName, agentKind: exe.agentKind, cwd: exe.cwd, herdrCommand: exe.herdrCommand ?? "herdr", agentCommand: exe.agentCommand ?? defaultAgentCommand(exe.agentKind) } : null,
exeConnections: connections.map(({ apiToken, ...connection }) => connection),
ampConnections: ampConnections.map(({ accessToken, ...connection }) => connection),
cloudflareTail: { count: (await this.tailIntegrations()).length, installations: await this.tailIntegrationStatus() },
cloudflareTail: { count: tailInstallations.length, installations: await this.tailIntegrationStatus(tailInstallations) },
});
}

Expand Down
25 changes: 25 additions & 0 deletions packages/app/test/run-inspection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ function tenantWithRows(rows: (query: string, ...params: unknown[]) => Record<st
}

describe("run invocation inspection", () => {
it("projects Tail references with one grouped count query", async () => {
const queries: string[] = [];
const tenant = tenantWithRows((query) => {
queries.push(query);
return [
{ integration_id: "tail-1", count: 2 },
{ integration_id: "tail-2", count: 1 },
];
});

const installations = [
{ integrationId: "tail-1", name: "Production", signingSecret: "secret-1", createdAt: "2026-09-16", updatedAt: "2026-09-16" },
{ integrationId: "tail-2", name: "Staging", signingSecret: "secret-2", createdAt: "2026-09-16", updatedAt: "2026-09-16" },
{ integrationId: "tail-3", name: "Unused", signingSecret: "secret-3", createdAt: "2026-09-16", updatedAt: "2026-09-16" },
];

await expect((tenant as any).tailIntegrationStatus(installations)).resolves.toEqual([
{ integrationId: "tail-1", name: "Production", createdAt: "2026-09-16", updatedAt: "2026-09-16", status: "connected", secretConfigured: true, referencedJobCount: 2 },
{ integrationId: "tail-2", name: "Staging", createdAt: "2026-09-16", updatedAt: "2026-09-16", status: "connected", secretConfigured: true, referencedJobCount: 1 },
{ integrationId: "tail-3", name: "Unused", createdAt: "2026-09-16", updatedAt: "2026-09-16", status: "connected", secretConfigured: true, referencedJobCount: 0 },
]);
expect(queries).toHaveLength(1);
expect(queries[0]).toContain("GROUP BY json_extract(config,'$.integrationId')");
});

it("preserves trigger slugs across edits and reordering", () => {
const tenant = Object.create(TenantV2.prototype) as TenantV2;
const existing = new Map([
Expand Down