mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-06 05:56:19 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The server has about 1,100 test and helper files in `server/src/__tests__` > - `server/tsconfig.json` excludes that directory, Vitest does not check types, and no script runs the tsconfig in that directory > - So a test can call a function with the wrong arguments and still pass, and no tool reports it > - This gap hid 2,168 real type errors, and some of them hid tests that did not test what they claim > - This pull request fixes all of these errors and adds the directory to the server layers from paperclipai/paperclip#18737 > - The benefit is that a type error in a server test now fails the typecheck, with no baseline and no backlog ## Linked Issues or Issue Description Refs paperclipai/paperclip#18737, which is merged and added the server layers. Refs paperclipai/paperclip#18738, which is merged and checks the test projects outside `pnpm -r`, so it is not a duplicate. Refs paperclipai/paperclip#18137, which records that this directory has no check. **What happened?** No tool checked the types of 1,074 of the 1,101 files in `server/src/__tests__`. I searched `package.json`, the workflows, and all tsconfig files. 27 files are in the program of another tsconfig, and these 27 have 0 errors. 11 of the 27 are in `helpers/maintenance/tsconfig.json`. No script ran that project when I measured this. paperclipai/paperclip#18738 now runs it. **Expected behavior** The server typecheck checks these files, and a type error fails the check. **Steps to reproduce** 1. On the base commit, run `tsc -p server/src/__tests__/tsconfig.json --noEmit`. It reports 6,536 errors and needs 12.3 GiB. 2. Add a type error to any file in `server/src/__tests__`. 3. Run `pnpm --filter @paperclipai/server typecheck`. It passes. **Paperclip version or commit** I measured the error breakdown below on commit `8dfd632452`, with TypeScript 7.0.2. The branch now includes master up to paperclipai/paperclip#18865. **Deployment mode** Not applicable. This issue applies to development and CI. No production source file in the server changes. ### Error breakdown Each row adds one change to the row above. | Step | Total errors | Change | Cause | | --- | --- | --- | --- | | Config as committed | 6,536 | | | | Add `src/types/*.d.ts` | 4,447 | -2,089 | Config. The Express request types were missing. | | Set `rootDir` to the repository root | 2,436 | -2,011 | Config. | | Set `allowImportingTsExtensions` | 2,181 | -255 | Config. Vitest accepts `.ts` imports. | | Add `ES2024.Promise` to `lib` | 2,138 | -43 | Config. Node 24 has `Promise.withResolvers`. | | Set `allowJs` for `.mjs` imports | 2,148 | +10 | Config. It removes 8 `TS7016` errors and shows new real errors. | | Set `declaration` to false | 2,142 | -6 | Config. Tests emit nothing. | | Count only files in `server/src` | 2,058 | -84 | Other packages: 53 Daytona, 29 Runner test, 2 UI. | So 4,478 of the 6,536 errors (69%) came from config or scope, and 2,058 are real type errors in 314 files. The 29 Runner test errors are also real, which gives 2,087 errors. Tests that master added after this measurement had 81 more errors, so this pull request fixes 2,168 errors. This table classifies the first 2,058 errors. | Kind of real error | Errors | | --- | --- | | Wrong argument or assignment type | 1,023 | | Stale or partial fixture objects | 525 | | Property that the type does not have | 317 | | Missing narrowing of null or unknown | 101 | | Implicit any | 60 | | Missing name or module | 16 | | Other | 16 | ### What the type errors hid Most errors were stale fixtures and loose mocks. These errors hid real test problems, and this pull request fixes them: - **A test that never ran.** `instrumentation.test.ts` required `sdk-trace-base`, which is not installed. So 3 span tests were skipped. They now run and pass. - **Assertions that could not fail.** - `issue-thread-interactions-service` used a company ID as an issue ID. - `status-card-evaluation-work` compared `[]` with `[]` in a rollback check. - `slack-conversation-lifecycle` read `item.issueId`, which does not exist. - `email-channels` used a permission key that does not exist. - `heartbeat-project-env` imported `LOW_TRUST_REVIEW_PRESET`, which is not exported. The value was undefined. - **Postgres processes that did not stop.** 11 test files called `stop` on the test database helper. That method does not exist, and the helper method is `cleanup`. - **Arguments that the service ignored.** - `methodKey` is now `connectionMethodKey` in the Daytona, Unikraft, 1Password, and Railway tests. - 108 calls passed `"owner-user"` to a parameter that expects an options object. - 9 chat wizard fixtures passed `managementContext` as `source`, so they ran `existing_app` and not `manifest`. - 2 tests passed a `{ userId }` actor that the function ignores. - Inserts into `environments` passed a `companyId` column that the table does not have. - **Problems in tests that master added during this work.** - `sandbox-creation-operations` read `database.connectionString` when an external test database was set. In that mode `database` is undefined, so the fixture would stop with a TypeError. It now uses the external URL. - `idle-completed-history` set a Dot operation to `dispatched`. That is a Muse status, and the Dot type does not have it. The fixture now uses `admitted`, which is a real in-flight Dot status. ### Possible product problems, not changed These may be real problems in production code or types. I did not change them, because this pull request does not change production behavior: - `decisions-service` `service.create` does not validate the lenient `cancel_issue_tree` input. - `createConnection` ignores `input.connectionPurpose`. - The `createConnection` route schema default stores `{}` for `transportConfig`. - `prepareManagedAiRuntime` accepted the invalid value `mode: "connection"`. - `createBinding` accepts invalid `projectionClass` strings outside class 3. - `ensureManagedProjectWorkspace` forwards an untyped `repoRef` by spread. - `routineVariableSchema.label` is optional, but `RoutineVariable.label` is required. - `ToolRunContext.projectId` may be too strict. - `withdrawInteraction` reads `issue.status`, which its type omits. - `issueService.list` and `reconcileNativeFinalizations` omit fields that they return at runtime. - `createGitHubExternalObjectProvider` handles `tokenProvider: null`, but its type forbids this value. ## What Changed - Fixed the 2,168 type errors. The diff changes 322 test and helper files. - Corrected `server/src/__tests__/tsconfig.json`. Editors and the typecheck now read the same options and report the same errors. - Added three `test-tree` layers to `server/scripts/typecheck-layers.mjs`. They read the server layers as declarations, and any error fails them. A hash of the path selects the shard, so a new file does not move other files. - Added `server/scripts/typecheck-stubs/daytona-sdk.d.ts`. Server tests reach Daytona plugin source, and the root install does not have `@daytonaio/sdk`. - Changed two imports in `ui/src/lib/issue-execution-policy.ts` to use `.js` extensions, because server tests import this file. - Made `declarationsConfig` and `--declarations-only` skip the `test-tree` layers, because these layers emit nothing. Other projects read only the source layers. Added a test for this. - Updated `doc/DEVELOPING.md`. ## Verification Run these commands: ```sh pnpm --filter @paperclipai/server typecheck pnpm exec vitest run server/scripts/typecheck-layers.test.mjs ``` Results on macOS (arm64), Node 24, 16 cores. Each check ran after the merge of paperclipai/paperclip#18738 unless the row says otherwise: | Check | Commit | Result | | --- | --- | --- | | Server typecheck, `PAPERCLIP_TYPECHECK_LOW_MEMORY=1`, all 7 layers | `6e45a08573` | Exit 0, 0 errors, 62 seconds, peak 3.52 GiB | | `node scripts/typecheck-test-projects.mjs --low-memory` | `a3306bd13e` | Exit 0, 0 errors, 42 seconds, peak 3.25 GiB | | The same script with `--reuse-declarations` | `1b878aabc0` | Exit 0, 0 errors | | `typecheck-layers.test.mjs` and `live-recovery-work.test.ts` | `01db5634e4` | 90 passed. These include real compiler runs for a pass, a type error, and an invalid tsconfig. | | `tsconfig.declarations.json` after a full server typecheck | `0fb1e4fb0a` | It references only `below`, `cycle`, and `above`. No generated config names a `tsconfig.layers.json` file. | | Owned runtime test in `idle-completed-history` | `e8f2f448ac` | Passed, with the fix that master later replaced | | `idle-incoming-wake`, `plugin-idle-manager`, and the changed `chat-channels` test | `6e45a08573` | 30 passed | | Runner `native-execution.test.ts` | `eab4dcc1f4` | 114 passed | | The 19 server test files that changed since `eab4dcc1f4`, and `typecheck-layers.test.mjs` | `259737b700` | 4,275 of 4,277 passed. The 2 failures are in `chat-channels` and are in the list of 7 below. | The peak is the largest single process, from `/usr/bin/time -l`. Peaks for the server typecheck were between 3.42 GiB and 3.56 GiB across 8 runs. Peaks for the test projects were 3.25 GiB and 3.37 GiB across 2 runs. I did not measure a cgroup. **Runtime check of the fixes.** Types do not prove that a test still works. So I ran all 309 changed server test files, 11,929 tests, before the rebase onto paperclipai/paperclip#18737: | Result | Tests | Detail | | --- | --- | --- | | Passed | 11,913 | Includes the 2 tests and the 54 `dot-runner` tests that passed in a later run, as described below. | | Failed | 7 | The same 7 tests also fail on the commit before the fixes. | | Skipped | 9 | These tests have their own skip conditions: `sentry` 5, and 1 each in `bundled-plugin-registration`, `customer-success-cloud`, `onepassword-connection`, and `workspace-runtime-https-live-exercise`. | The 7 tests that fail with and without this change, on my machine: - 3 tests in `chat-channels` and `email-channels` stop with `ENOENT` on a `SKILL.md` file. The path is in the parent checkout, above the git worktree that I used, so I expect that the worktree is the cause. I did not prove this. - `workspace-instance-cleanup` compares `/private/var/...` with `/var/...`. This is a macOS symlink difference. - 2 tests in `git-reproducible-managed-checkouts` get `unknown_base_git_files` and expect `unpushed_managed_checkout`. I did not find the cause. - 1 more test in `chat-channels`, `materializes direct external-chat finals once`, gets `undefined`. I did not find the cause. CI is the check for these 7 tests. `ci / verify` passed on `eab4dcc1f4`. Failures during this work: - My fix to `agent-runtime-connector-access` changed an invalid permission key in the setup, but not in the assertion. The runtime check found this. I corrected the assertion, and the file passes. - `heartbeat-plugin-environment` failed one wait in the full run. It passed three times alone, so I think that load caused the failure. It can fail again under load. - `dot-runner` skipped all 54 tests in the full run because `cargo` was not on my `PATH`. It then passed 54 of 54 with the toolchain on the `PATH`. - My first `lib` value removed the default DOM types, and the error count went up by 375. I added the DOM libraries. - My Daytona stub with bare `any` left 48 errors, because generic helpers then inferred `unknown`. I added shapes that return promises. - One fix to `agent-secrets-routes` used `class_3_static_lease`, and the test failed. That class allows only specific paths. I reverted to `unclassified`. - `ci / General tests (server (8/12))` failed on `259737b700` because of the flaky port in `idle-completed-history`. paperclipai/paperclip#18853 fixed this test on master, so this pull request keeps that fix. **Audit of the diff.** I counted these patterns in added and removed lines, to find fixes that only hide an error: | Pattern | Added | Removed | | --- | --- | --- | | `@ts-ignore` | 0 | 0 | | `@ts-expect-error` | 0 | 1 | | `.skip` | 0 | 0 | | `as any` | 9 | 9 | | `: any` | 11 | 2 | | `as never` | 8 | 2 | | `as unknown as` | 35 | 4 | | `Promise<unknown>` | 16 | 5 | | `expect(` | 128 | 113 | No hunk removes more `expect(` calls than it adds. Three removals of test content were intentional, and I checked each one: - `muse-control` removed `signalToken`. Line 1012 already asserts that it is absent. - `merged-pr-confirmation-sweep` removed legacy aliases. Other tests cover them. - `heartbeat-workspace-branch-containment` removed a `finalize` branch that no test row can reach. Some partial fixtures stay unchecked through `as unknown as` and `Promise<unknown>`, mostly in `issue-agent-mutation-ownership-routes` and `issue-comment-reopen-routes`. **Accuracy of the check.** One program over the tree and the three shards reported the same errors at the same positions. Memory, as the peak of the largest process on one thread, was 3.93 GiB for one program and 2.43 GiB for the largest shard. I measured these two values before the fixes. Not run or not proven: - I did not run the full `pnpm test:run`, or a root `pnpm build`. I expect CI to run the full suites. - I did not run the 4 GiB container check, or the full `scripts/typecheck-low-memory.mjs`. The peaks above come from macOS, so they are not a Linux cgroup measurement. - I did not run the UI typecheck after the merges. - `workspace-runtime-https-live-exercise` is skipped, so its `cleanup` fix did not run. ## Risks - **A large diff in test files.** 328 files change. A pull request that edits the same tests can get merge conflicts. New tests on master can also add type errors before this merges. Any such error fails this check and needs a fix here. - **A higher cost for changes to source types.** A change to a type can add errors in test files that the author did not touch. The author must then fix them. This is the purpose of the check, but it is new work. - **Changed test behavior.** Some tests now run paths that they did not run before, such as the 9 chat wizard fixtures and the 3 span tests. They pass here, but they can be more sensitive to timing or to the environment. - **The Daytona stub can go stale.** The stub is written by hand. If the plugin uses a new SDK member, the typecheck reports an error until someone updates the stub. - **The release path.** `release-verify.yml` and `scripts/release.sh` run `pnpm -r typecheck`, so they now run this check. - **The tsconfig change.** The test transform reads `server/src/__tests__/tsconfig.json`. The options that I changed are for type checks, and the runs above passed. - **A gap that remains.** Tsconfigs in `packages/paperclip-runner` and in most sandbox provider plugins exclude `*.test.ts`. This check does not read most of those test files, so they can still drift. That work is separate from this pull request. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used Anthropic Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with reasoning, tool use, code execution, and subagents. The runtime does not show the context window size. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] I have run tests locally and they pass (7 tests fail locally, with and without this change. See Verification.) - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1021 lines
38 KiB
TypeScript
1021 lines
38 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { eq } from "drizzle-orm";
|
|
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
import {
|
|
activityLog,
|
|
agents,
|
|
agentWakeupRequests,
|
|
approvals,
|
|
companies,
|
|
createDb,
|
|
applyPendingMigrations,
|
|
heartbeatRuns,
|
|
issueApprovals,
|
|
issueRelations,
|
|
issueThreadInteractions,
|
|
issues,
|
|
} from "@paperclipai/db";
|
|
import {
|
|
getEmbeddedPostgresTestSupport,
|
|
startEmbeddedPostgresTestDatabase,
|
|
} from "./helpers/embedded-postgres.js";
|
|
import type { Issue } from "@paperclipai/shared";
|
|
import { issueService } from "../services/issues.js";
|
|
import { buildIssueGraphLivenessIncidentKey } from "../services/recovery/origins.js";
|
|
|
|
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
|
|
|
|
const externalUrl = resolveExternalTestDatabaseUrl("PAPERCLIP_BLOCKER_ATTENTION_TEST_DATABASE_URL");
|
|
const embeddedPostgresSupport = externalUrl ? { supported: true } : await getEmbeddedPostgresTestSupport();
|
|
const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip;
|
|
|
|
if (!embeddedPostgresSupport.supported) {
|
|
console.warn(
|
|
`Skipping embedded Postgres issue blocker attention tests on this host: ${embeddedPostgresSupport.reason ?? "unsupported environment"}`,
|
|
);
|
|
}
|
|
|
|
// The inferred list() return type drops the attention fields that its rows carry at runtime.
|
|
type IssueServiceWithListProjection = Omit<ReturnType<typeof issueService>, "list"> & {
|
|
list(
|
|
...args: Parameters<ReturnType<typeof issueService>["list"]>
|
|
): Promise<Array<Awaited<ReturnType<ReturnType<typeof issueService>["list"]>>[number] & Pick<Issue, "blockedBy" | "blockerAttention" | "blockedInboxAttention">>>;
|
|
};
|
|
|
|
describeEmbeddedPostgres("issue blocker attention", () => {
|
|
let db!: ReturnType<typeof createDb>;
|
|
let svc!: IssueServiceWithListProjection;
|
|
let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;
|
|
|
|
beforeAll(async () => {
|
|
if (externalUrl) await applyPendingMigrations(externalUrl);
|
|
else tempDb = await startEmbeddedPostgresTestDatabase("paperclip-issue-blocker-attention-");
|
|
db = createDb(externalUrl ?? tempDb!.connectionString, { maxConnections: 6 });
|
|
svc = issueService(db);
|
|
}, 20_000);
|
|
|
|
afterEach(async () => {
|
|
await db.delete(issueThreadInteractions);
|
|
await db.delete(issueApprovals);
|
|
await db.delete(approvals);
|
|
await db.delete(activityLog);
|
|
await db.delete(heartbeatRuns);
|
|
await db.delete(agentWakeupRequests);
|
|
await db.delete(issueRelations);
|
|
await db.delete(issues);
|
|
await db.delete(agents);
|
|
await db.delete(companies);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await db?.$client.end({ timeout: 1 });
|
|
await tempDb?.cleanup();
|
|
});
|
|
|
|
async function createCompany(prefix = "PBA") {
|
|
const companyId = randomUUID();
|
|
const agentId = randomUUID();
|
|
const pausedAgentId = randomUUID();
|
|
await db.insert(companies).values({
|
|
id: companyId,
|
|
name: `Company ${prefix}`,
|
|
issuePrefix: prefix,
|
|
requireBoardApprovalForNewAgents: false,
|
|
});
|
|
await db.insert(agents).values([
|
|
{
|
|
id: agentId,
|
|
companyId,
|
|
name: `${prefix} Agent`,
|
|
role: "engineer",
|
|
status: "idle",
|
|
},
|
|
{
|
|
id: pausedAgentId,
|
|
companyId,
|
|
name: `${prefix} Paused`,
|
|
role: "engineer",
|
|
status: "paused",
|
|
},
|
|
]);
|
|
return { companyId, agentId, pausedAgentId };
|
|
}
|
|
|
|
async function insertIssue(input: {
|
|
companyId: string;
|
|
id?: string;
|
|
identifier: string;
|
|
title: string;
|
|
status: string;
|
|
parentId?: string | null;
|
|
assigneeAgentId?: string | null;
|
|
assigneeUserId?: string | null;
|
|
originKind?: string | null;
|
|
originId?: string | null;
|
|
originFingerprint?: string | null;
|
|
executionState?: Record<string, unknown> | null;
|
|
description?: string | null;
|
|
}) {
|
|
const id = input.id ?? randomUUID();
|
|
await db.insert(issues).values({
|
|
id,
|
|
companyId: input.companyId,
|
|
identifier: input.identifier,
|
|
title: input.title,
|
|
status: input.status,
|
|
priority: "medium",
|
|
parentId: input.parentId ?? null,
|
|
assigneeAgentId: input.assigneeAgentId ?? null,
|
|
assigneeUserId: input.assigneeUserId ?? null,
|
|
originKind: input.originKind ?? "manual",
|
|
originId: input.originId ?? null,
|
|
originFingerprint: input.originFingerprint ?? "default",
|
|
executionState: input.executionState ?? null,
|
|
description: input.description ?? null,
|
|
});
|
|
return id;
|
|
}
|
|
|
|
async function block(input: { companyId: string; blockerIssueId: string; blockedIssueId: string }) {
|
|
await db.insert(issueRelations).values({
|
|
companyId: input.companyId,
|
|
issueId: input.blockerIssueId,
|
|
relatedIssueId: input.blockedIssueId,
|
|
type: "blocks",
|
|
});
|
|
}
|
|
|
|
async function activeRun(input: {
|
|
companyId: string;
|
|
agentId: string;
|
|
issueId: string;
|
|
status?: string;
|
|
current?: boolean;
|
|
scheduledRetryAt?: Date;
|
|
}) {
|
|
const runId = randomUUID();
|
|
await db.insert(heartbeatRuns).values({
|
|
id: runId,
|
|
companyId: input.companyId,
|
|
agentId: input.agentId,
|
|
status: input.status ?? "running",
|
|
contextSnapshot: { issueId: input.issueId },
|
|
scheduledRetryAt: input.scheduledRetryAt,
|
|
});
|
|
if (input.current !== false) {
|
|
await db.update(issues).set({ executionRunId: runId }).where(eq(issues.id, input.issueId));
|
|
}
|
|
return runId;
|
|
}
|
|
|
|
it("classifies a blocked parent as covered when its child has a running execution path", async () => {
|
|
const { companyId, agentId } = await createCompany("PBC");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBC-1", title: "Parent", status: "blocked" });
|
|
const childId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBC-2",
|
|
title: "Running child",
|
|
status: "todo",
|
|
parentId,
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: childId, blockedIssueId: parentId });
|
|
await activeRun({ companyId, agentId, issueId: childId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "covered",
|
|
reason: "active_child",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 1,
|
|
attentionBlockerCount: 0,
|
|
sampleBlockerIdentifier: "PBC-2",
|
|
});
|
|
});
|
|
|
|
it("classifies an assigned backlog blocker leaf without a waiting path as attention-needed", async () => {
|
|
const { companyId, agentId } = await createCompany("PBB");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBB-1", title: "Parent", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBB-2",
|
|
title: "Parked assigned blocker",
|
|
status: "backlog",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "attention_required",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 0,
|
|
stalledBlockerCount: 0,
|
|
attentionBlockerCount: 1,
|
|
sampleBlockerIdentifier: "PBB-2",
|
|
});
|
|
});
|
|
|
|
it("treats a human-owned backlog blocker as a covered waiting path", async () => {
|
|
const { companyId } = await createCompany("PBU");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBU-1", title: "Parent", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBU-2",
|
|
title: "Human-owned parked blocker",
|
|
status: "backlog",
|
|
assigneeUserId: "board-user-1",
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "covered",
|
|
reason: "active_dependency",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 1,
|
|
attentionBlockerCount: 0,
|
|
sampleBlockerIdentifier: "PBU-2",
|
|
});
|
|
});
|
|
|
|
it("keeps mixed blockers attention-required when any path lacks active work", async () => {
|
|
const { companyId, agentId } = await createCompany("PBM");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBM-1", title: "Parent", status: "blocked" });
|
|
const activeChildId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBM-2",
|
|
title: "Running child",
|
|
status: "todo",
|
|
parentId,
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const idleBlockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBM-3",
|
|
title: "Idle blocker",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: activeChildId, blockedIssueId: parentId });
|
|
await block({ companyId, blockerIssueId: idleBlockerId, blockedIssueId: parentId });
|
|
await activeRun({ companyId, agentId, issueId: activeChildId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "attention_required",
|
|
unresolvedBlockerCount: 2,
|
|
coveredBlockerCount: 1,
|
|
attentionBlockerCount: 1,
|
|
sampleBlockerIdentifier: "PBM-3",
|
|
});
|
|
});
|
|
|
|
it("ignores cancelled direct children when counting unresolved blocker attention", async () => {
|
|
const { companyId, agentId } = await createCompany("PBD");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBD-1", title: "Parent", status: "blocked" });
|
|
const activeBlockerOneId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBD-2",
|
|
title: "Running dependency one",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const activeBlockerTwoId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBD-3",
|
|
title: "Running dependency two",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await insertIssue({
|
|
companyId,
|
|
identifier: "PBD-4",
|
|
title: "Cancelled child",
|
|
status: "cancelled",
|
|
parentId,
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: activeBlockerOneId, blockedIssueId: parentId });
|
|
await block({ companyId, blockerIssueId: activeBlockerTwoId, blockedIssueId: parentId });
|
|
await activeRun({ companyId, agentId, issueId: activeBlockerOneId });
|
|
await activeRun({ companyId, agentId, issueId: activeBlockerTwoId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "covered",
|
|
reason: "active_dependency",
|
|
unresolvedBlockerCount: 2,
|
|
coveredBlockerCount: 2,
|
|
stalledBlockerCount: 0,
|
|
attentionBlockerCount: 0,
|
|
});
|
|
expect(parent?.blockerAttention?.sampleBlockerIdentifier).not.toBe("PBD-4");
|
|
});
|
|
|
|
it("covers recursive blocker chains when the downstream leaf has active work", async () => {
|
|
const { companyId, agentId } = await createCompany("PBR");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBR-1", title: "Parent", status: "blocked" });
|
|
const blockerId = await insertIssue({ companyId, identifier: "PBR-2", title: "Blocked dependency", status: "blocked" });
|
|
const leafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBR-3",
|
|
title: "Running leaf",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
await block({ companyId, blockerIssueId: leafId, blockedIssueId: blockerId });
|
|
await activeRun({ companyId, agentId, issueId: leafId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "covered",
|
|
reason: "active_dependency",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 1,
|
|
attentionBlockerCount: 0,
|
|
sampleBlockerIdentifier: "PBR-3",
|
|
});
|
|
});
|
|
|
|
it("does not let another company's active run cover the blocker", async () => {
|
|
const { companyId, agentId } = await createCompany("PBS");
|
|
const other = await createCompany("PBT");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBS-1", title: "Parent", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBS-2",
|
|
title: "Same-company blocker",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
await activeRun({ companyId: other.companyId, agentId: other.agentId, issueId: blockerId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "attention_required",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 0,
|
|
attentionBlockerCount: 1,
|
|
sampleBlockerIdentifier: "PBS-2",
|
|
});
|
|
});
|
|
|
|
it("does not cover a blocker from a stale run the issue no longer owns", async () => {
|
|
const { companyId, agentId } = await createCompany("PBX");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBX-1", title: "Parent", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBX-2",
|
|
title: "Previously running blocker",
|
|
status: "blocked",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
await activeRun({ companyId, agentId, issueId: blockerId, current: false });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "attention_required",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 0,
|
|
attentionBlockerCount: 1,
|
|
sampleBlockerIdentifier: "PBX-2",
|
|
});
|
|
});
|
|
|
|
it("flags a chain whose leaf is in_review without an action path as stalled", async () => {
|
|
const { companyId, agentId } = await createCompany("PBV");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBV-1", title: "Parent", status: "blocked" });
|
|
const reviewLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBV-2",
|
|
title: "Stalled review leaf",
|
|
status: "in_review",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: reviewLeafId, blockedIssueId: parentId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "stalled",
|
|
reason: "stalled_review",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 0,
|
|
stalledBlockerCount: 1,
|
|
attentionBlockerCount: 0,
|
|
sampleBlockerIdentifier: "PBV-2",
|
|
sampleStalledBlockerIdentifier: "PBV-2",
|
|
});
|
|
});
|
|
|
|
it("does not flag an in_review leaf as stalled when an active run is still progressing it", async () => {
|
|
const { companyId, agentId } = await createCompany("PBW");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBW-1", title: "Parent", status: "blocked" });
|
|
const reviewLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBW-2",
|
|
title: "Active review leaf",
|
|
status: "in_review",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: reviewLeafId, blockedIssueId: parentId });
|
|
await activeRun({ companyId, agentId, issueId: reviewLeafId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "covered",
|
|
stalledBlockerCount: 0,
|
|
});
|
|
});
|
|
|
|
it("flags a deep chain whose leaf is stalled in_review through multiple layers", async () => {
|
|
const { companyId, agentId } = await createCompany("PBZ");
|
|
const rootId = await insertIssue({ companyId, identifier: "PBZ-1", title: "Root", status: "blocked" });
|
|
const midId = await insertIssue({ companyId, identifier: "PBZ-2", title: "Mid blocker", status: "blocked" });
|
|
const leafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBZ-3",
|
|
title: "Stalled leaf",
|
|
status: "in_review",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: midId, blockedIssueId: rootId });
|
|
await block({ companyId, blockerIssueId: leafId, blockedIssueId: midId });
|
|
|
|
const root = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === rootId);
|
|
|
|
expect(root?.blockerAttention).toMatchObject({
|
|
state: "stalled",
|
|
reason: "stalled_review",
|
|
stalledBlockerCount: 1,
|
|
sampleStalledBlockerIdentifier: "PBZ-3",
|
|
});
|
|
});
|
|
|
|
it("returns the direct path and link details when an intermediate blocker is selected", async () => {
|
|
const { companyId, agentId } = await createCompany("PBI");
|
|
const rootId = await insertIssue({ companyId, identifier: "PBI-1", title: "Root", status: "blocked" });
|
|
const directId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBI-2",
|
|
title: "Direct blocker",
|
|
status: "blocked",
|
|
});
|
|
const intermediateId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBI-3",
|
|
title: "Stalled intermediate review",
|
|
status: "in_review",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const leafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBI-4",
|
|
title: "Downstream leaf",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: directId, blockedIssueId: rootId });
|
|
await block({ companyId, blockerIssueId: intermediateId, blockedIssueId: directId });
|
|
await block({ companyId, blockerIssueId: leafId, blockedIssueId: intermediateId });
|
|
|
|
const root = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === rootId);
|
|
|
|
expect(root?.blockerAttention).toMatchObject({
|
|
state: "stalled",
|
|
directBlockerIssueId: directId,
|
|
terminalBlockerIssueId: intermediateId,
|
|
terminalBlocker: {
|
|
id: intermediateId,
|
|
identifier: "PBI-3",
|
|
title: "Stalled intermediate review",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("prefers needs_attention over stalled when the chain also has a hard attention case", async () => {
|
|
const { companyId, agentId } = await createCompany("PBQ");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBQ-1", title: "Parent", status: "blocked" });
|
|
const reviewLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBQ-2",
|
|
title: "Stalled review leaf",
|
|
status: "in_review",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const cancelledLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBQ-3",
|
|
title: "Cancelled blocker",
|
|
status: "cancelled",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: reviewLeafId, blockedIssueId: parentId });
|
|
await block({ companyId, blockerIssueId: cancelledLeafId, blockedIssueId: parentId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "attention_required",
|
|
coveredBlockerCount: 0,
|
|
stalledBlockerCount: 1,
|
|
attentionBlockerCount: 1,
|
|
sampleStalledBlockerIdentifier: "PBQ-2",
|
|
});
|
|
});
|
|
|
|
it("treats open liveness escalation blockers as covered waiting paths", async () => {
|
|
const { companyId, agentId } = await createCompany("PBL");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBL-1", title: "Parent", status: "blocked" });
|
|
const cancelledLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBL-2",
|
|
title: "Cancelled blocker",
|
|
status: "cancelled",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const incidentKey = [
|
|
"harness_liveness",
|
|
companyId,
|
|
parentId,
|
|
"blocked_by_cancelled_issue",
|
|
cancelledLeafId,
|
|
].join(":");
|
|
const escalationId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBL-3",
|
|
title: "Liveness escalation",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
originKind: "harness_liveness_escalation",
|
|
originId: incidentKey,
|
|
originFingerprint: [
|
|
"harness_liveness_leaf",
|
|
companyId,
|
|
"blocked_by_cancelled_issue",
|
|
cancelledLeafId,
|
|
].join(":"),
|
|
});
|
|
await block({ companyId, blockerIssueId: cancelledLeafId, blockedIssueId: parentId });
|
|
await block({ companyId, blockerIssueId: escalationId, blockedIssueId: parentId });
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked,todo" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "covered",
|
|
reason: "active_dependency",
|
|
unresolvedBlockerCount: 2,
|
|
coveredBlockerCount: 2,
|
|
attentionBlockerCount: 0,
|
|
});
|
|
});
|
|
|
|
it("does not treat cancelled liveness escalation issues as covered waiting paths", async () => {
|
|
const { companyId, agentId } = await createCompany("PBLX");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBLX-1", title: "Parent", status: "blocked" });
|
|
const cancelledLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBLX-2",
|
|
title: "Cancelled blocker",
|
|
status: "cancelled",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await insertIssue({
|
|
companyId,
|
|
identifier: "PBLX-3",
|
|
title: "Cancelled liveness escalation",
|
|
status: "cancelled",
|
|
assigneeAgentId: agentId,
|
|
originKind: "harness_liveness_escalation",
|
|
originId: [
|
|
"harness_liveness",
|
|
companyId,
|
|
parentId,
|
|
"blocked_by_cancelled_issue",
|
|
cancelledLeafId,
|
|
].join(":"),
|
|
});
|
|
await block({ companyId, blockerIssueId: cancelledLeafId, blockedIssueId: parentId });
|
|
|
|
const parent = (await svc.list(companyId, { attention: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockedInboxAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "blocked_by_cancelled_issue",
|
|
leafIssue: { id: cancelledLeafId, identifier: "PBLX-2" },
|
|
});
|
|
});
|
|
|
|
it("does not treat an expired scheduled retry as actively covered work", async () => {
|
|
const pinnedNow = new Date("2026-08-20T12:00:00.000Z");
|
|
const expiredRetryAt = new Date(pinnedNow.getTime() - 60_000);
|
|
const { companyId, agentId } = await createCompany("PBY");
|
|
const parentId = await insertIssue({ companyId, identifier: "PBY-1", title: "Parent", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "PBY-2",
|
|
title: "Retrying blocker",
|
|
status: "blocked",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
await activeRun({
|
|
companyId,
|
|
agentId,
|
|
issueId: blockerId,
|
|
status: "scheduled_retry",
|
|
scheduledRetryAt: expiredRetryAt,
|
|
});
|
|
|
|
const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId);
|
|
|
|
expect(parent?.blockerAttention).toMatchObject({
|
|
state: "needs_attention",
|
|
reason: "attention_required",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 0,
|
|
attentionBlockerCount: 1,
|
|
sampleBlockerIdentifier: "PBY-2",
|
|
});
|
|
});
|
|
|
|
it("returns blocked inbox attention for an unassigned blocker leaf and supports count/search", async () => {
|
|
const { companyId } = await createCompany("BIA");
|
|
const parentId = await insertIssue({ companyId, identifier: "BIA-1", title: "Blocked source", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "BIA-2",
|
|
title: "Unassigned leaf",
|
|
status: "todo",
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked", q: "BIA-2" });
|
|
|
|
expect(rows).toHaveLength(1);
|
|
expect(rows[0]?.id).toBe(parentId);
|
|
expect(rows[0]?.blockedBy).toEqual([
|
|
expect.objectContaining({ id: blockerId, identifier: "BIA-2" }),
|
|
]);
|
|
expect(rows[0]?.blockedInboxAttention).toMatchObject({
|
|
kind: "blocked",
|
|
state: "needs_attention",
|
|
reason: "blocked_by_unassigned_issue",
|
|
severity: "critical",
|
|
owner: { type: "unknown", agentId: null, userId: null },
|
|
action: { label: "Assign blocker" },
|
|
leafIssue: { id: blockerId, identifier: "BIA-2" },
|
|
redaction: { secretFieldsOmitted: true },
|
|
});
|
|
await expect(svc.count(companyId, { attention: "blocked" })).resolves.toBe(1);
|
|
});
|
|
|
|
it("surfaces cancelled-blocker attention on an assigned todo source", async () => {
|
|
const { companyId, agentId } = await createCompany("BICX");
|
|
const sourceId = await insertIssue({
|
|
companyId,
|
|
identifier: "BICX-1",
|
|
title: "Dispatch-suppressed source",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "BICX-2",
|
|
title: "Cancelled dependency",
|
|
status: "cancelled",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: sourceId });
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked" });
|
|
const source = rows.find((issue) => issue.id === sourceId);
|
|
|
|
expect(source?.blockedInboxAttention).toMatchObject({
|
|
kind: "blocked",
|
|
state: "needs_attention",
|
|
reason: "blocked_by_cancelled_issue",
|
|
owner: { type: "agent", agentId },
|
|
action: { label: "Replace blocker" },
|
|
leafIssue: { id: blockerId, identifier: "BICX-2" },
|
|
});
|
|
});
|
|
|
|
it("redacts external wait details from blocked inbox payloads and search", async () => {
|
|
const { companyId } = await createCompany("BIX");
|
|
const owner = "Private Vendor Security Team";
|
|
const action = "Send the confidential access token for customer Alpha";
|
|
const issueId = await insertIssue({
|
|
companyId,
|
|
identifier: "BIX-1",
|
|
title: "Blocked on vendor",
|
|
status: "blocked",
|
|
description: [
|
|
"Public context stays visible.",
|
|
`external owner: ${owner}`,
|
|
`external action: ${action}`,
|
|
"Continue after the vendor confirms receipt.",
|
|
].join("\n"),
|
|
});
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked" });
|
|
const issue = rows.find((row) => row.id === issueId);
|
|
|
|
expect(issue?.description).toContain("Public context stays visible.");
|
|
expect(issue?.description).toContain("Continue after the vendor confirms receipt.");
|
|
expect(issue?.description).not.toContain(owner);
|
|
expect(issue?.description).not.toContain(action);
|
|
expect(issue?.blockedInboxAttention).toMatchObject({
|
|
state: "external_wait",
|
|
reason: "external_owner_action",
|
|
owner: { type: "external", label: null },
|
|
action: { label: "External owner action", detail: null },
|
|
redaction: { externalDetailsRedacted: true, secretFieldsOmitted: true },
|
|
});
|
|
expect(JSON.stringify(issue?.blockedInboxAttention)).not.toContain(owner);
|
|
expect(JSON.stringify(issue?.blockedInboxAttention)).not.toContain(action);
|
|
|
|
await expect(svc.list(companyId, { attention: "blocked", q: owner })).resolves.toEqual([]);
|
|
await expect(svc.count(companyId, { attention: "blocked", q: action })).resolves.toBe(0);
|
|
await expect(svc.count(companyId, { attention: "blocked", q: "Public context" })).resolves.toBe(1);
|
|
});
|
|
|
|
it("excludes healthy active blockers from blocked inbox attention", async () => {
|
|
const { companyId, agentId } = await createCompany("BIB");
|
|
const parentId = await insertIssue({ companyId, identifier: "BIB-1", title: "Blocked source", status: "blocked" });
|
|
const blockerId = await insertIssue({
|
|
companyId,
|
|
identifier: "BIB-2",
|
|
title: "Running leaf",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: blockerId, blockedIssueId: parentId });
|
|
await activeRun({ companyId, agentId, issueId: blockerId });
|
|
|
|
expect(await svc.list(companyId, { attention: "blocked" })).toEqual([]);
|
|
});
|
|
|
|
it("classifies assigned backlog and invalid review leaves for blocked inbox attention", async () => {
|
|
const { companyId, agentId, pausedAgentId } = await createCompany("BIC");
|
|
const backlogParentId = await insertIssue({ companyId, identifier: "BIC-1", title: "Blocked by parked work", status: "blocked" });
|
|
const backlogLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "BIC-2",
|
|
title: "Parked blocker",
|
|
status: "backlog",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await block({ companyId, blockerIssueId: backlogLeafId, blockedIssueId: backlogParentId });
|
|
|
|
const reviewId = await insertIssue({
|
|
companyId,
|
|
identifier: "BIC-3",
|
|
title: "Invalid review",
|
|
status: "in_review",
|
|
assigneeAgentId: agentId,
|
|
executionState: {
|
|
status: "pending",
|
|
currentStageId: null,
|
|
currentStageIndex: null,
|
|
currentStageType: "review",
|
|
currentParticipant: { type: "agent", agentId: pausedAgentId },
|
|
returnAssignee: null,
|
|
reviewRequest: null,
|
|
completedStageIds: [],
|
|
lastDecisionId: null,
|
|
lastDecisionOutcome: null,
|
|
},
|
|
});
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked" });
|
|
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
|
|
expect(byId.get(backlogParentId)?.blockedInboxAttention).toMatchObject({
|
|
reason: "blocked_by_assigned_backlog_issue",
|
|
severity: "high",
|
|
owner: { type: "agent", agentId },
|
|
leafIssue: { id: backlogLeafId },
|
|
});
|
|
expect(byId.get(reviewId)?.blockedInboxAttention).toMatchObject({
|
|
reason: "invalid_review_participant",
|
|
severity: "critical",
|
|
action: { label: "Repair review participant" },
|
|
});
|
|
});
|
|
|
|
it("classifies recovery issues and missing successful-run dispositions", async () => {
|
|
const { companyId, agentId } = await createCompany("BID");
|
|
const sourceId = await insertIssue({ companyId, identifier: "BID-1", title: "Stopped source", status: "blocked" });
|
|
const leafId = await insertIssue({ companyId, identifier: "BID-2", title: "Stopped leaf", status: "todo" });
|
|
const recoveryId = await insertIssue({
|
|
companyId,
|
|
identifier: "BID-3",
|
|
title: "Recovery issue",
|
|
status: "todo",
|
|
assigneeAgentId: agentId,
|
|
originKind: "harness_liveness_escalation",
|
|
originId: buildIssueGraphLivenessIncidentKey({
|
|
companyId,
|
|
issueId: sourceId,
|
|
state: "blocked_by_unassigned_issue",
|
|
blockerIssueId: leafId,
|
|
}),
|
|
});
|
|
const handoffId = await insertIssue({
|
|
companyId,
|
|
identifier: "BID-4",
|
|
title: "Needs disposition",
|
|
status: "in_progress",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
await db.insert(activityLog).values({
|
|
companyId,
|
|
actorType: "system",
|
|
actorId: "system",
|
|
action: "issue.successful_run_handoff_required",
|
|
entityType: "issue",
|
|
entityId: handoffId,
|
|
agentId,
|
|
details: { sourceRunId: randomUUID(), detectedProgressSummary: "Progress was made" },
|
|
});
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked" });
|
|
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
|
|
expect(byId.get(recoveryId)?.blockedInboxAttention).toMatchObject({
|
|
state: "recovery_open",
|
|
reason: "open_recovery_issue",
|
|
sourceIssue: { id: sourceId },
|
|
leafIssue: { id: leafId },
|
|
recoveryIssue: { id: recoveryId },
|
|
});
|
|
expect(byId.get(handoffId)?.blockedInboxAttention).toMatchObject({
|
|
state: "missing_disposition",
|
|
reason: "missing_successful_run_disposition",
|
|
owner: { type: "agent", agentId },
|
|
action: { label: "Choose disposition" },
|
|
});
|
|
|
|
const handoffRunId = await activeRun({ companyId, agentId, issueId: handoffId, current: false });
|
|
const liveRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(liveRows.some((row) => row.id === handoffId)).toBe(false);
|
|
|
|
await db.update(heartbeatRuns).set({ status: "succeeded" }).where(eq(heartbeatRuns.id, handoffRunId));
|
|
const stoppedRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(stoppedRows.find((row) => row.id === handoffId)?.blockedInboxAttention).toMatchObject({
|
|
state: "missing_disposition",
|
|
reason: "missing_successful_run_disposition",
|
|
});
|
|
|
|
const scheduledRetryRunId = randomUUID();
|
|
await db.insert(heartbeatRuns).values({
|
|
id: scheduledRetryRunId,
|
|
companyId,
|
|
agentId,
|
|
status: "scheduled_retry",
|
|
contextSnapshot: { taskId: handoffId },
|
|
scheduledRetryAt: new Date(Date.now() + 60_000),
|
|
scheduledRetryAttempt: 1,
|
|
});
|
|
const scheduledRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(scheduledRows.some((row) => row.id === handoffId)).toBe(false);
|
|
|
|
await db.update(heartbeatRuns).set({ status: "succeeded" }).where(eq(heartbeatRuns.id, scheduledRetryRunId));
|
|
const exhaustedRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(exhaustedRows.find((row) => row.id === handoffId)?.blockedInboxAttention).toMatchObject({
|
|
state: "missing_disposition",
|
|
reason: "missing_successful_run_disposition",
|
|
});
|
|
|
|
await db.insert(activityLog).values({
|
|
companyId,
|
|
actorType: "system",
|
|
actorId: "system",
|
|
action: "issue.successful_run_handoff_escalated",
|
|
entityType: "issue",
|
|
entityId: handoffId,
|
|
agentId,
|
|
details: { sourceRunId: randomUUID() },
|
|
});
|
|
const escalatedRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(escalatedRows.find((row) => row.id === handoffId)?.blockedInboxAttention).toMatchObject({
|
|
state: "missing_disposition",
|
|
reason: "missing_successful_run_disposition",
|
|
});
|
|
|
|
const escalatedLiveRunId = await activeRun({ companyId, agentId, issueId: handoffId, current: false });
|
|
const escalatedLiveRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(escalatedLiveRows.some((row) => row.id === handoffId)).toBe(false);
|
|
|
|
await db.update(heartbeatRuns).set({ status: "succeeded" }).where(eq(heartbeatRuns.id, escalatedLiveRunId));
|
|
const escalatedStoppedRows = await svc.list(companyId, { attention: "blocked" });
|
|
expect(escalatedStoppedRows.find((row) => row.id === handoffId)?.blockedInboxAttention).toMatchObject({
|
|
state: "missing_disposition",
|
|
reason: "missing_successful_run_disposition",
|
|
});
|
|
});
|
|
|
|
it("applies assigneeAgentId='null' as an IS NULL filter on the blocked-inbox path", async () => {
|
|
const { companyId, agentId } = await createCompany("BAN");
|
|
const unassignedParentId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAN-1",
|
|
title: "Unassigned blocked parent",
|
|
status: "blocked",
|
|
});
|
|
const unassignedLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAN-2",
|
|
title: "Unassigned leaf",
|
|
status: "todo",
|
|
});
|
|
await block({ companyId, blockerIssueId: unassignedLeafId, blockedIssueId: unassignedParentId });
|
|
|
|
const assignedParentId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAN-3",
|
|
title: "Assigned blocked parent",
|
|
status: "blocked",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const assignedLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAN-4",
|
|
title: "Unassigned leaf for assigned parent",
|
|
status: "todo",
|
|
});
|
|
await block({ companyId, blockerIssueId: assignedLeafId, blockedIssueId: assignedParentId });
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked", assigneeAgentId: "null" });
|
|
expect(rows.map((row) => row.id)).toEqual([unassignedParentId]);
|
|
|
|
await expect(svc.count(companyId, { attention: "blocked", assigneeAgentId: "null" })).resolves.toBe(1);
|
|
});
|
|
|
|
it("applies a UUID assigneeAgentId filter on the blocked-inbox path", async () => {
|
|
const { companyId, agentId } = await createCompany("BAU");
|
|
const unassignedParentId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAU-1",
|
|
title: "Unassigned blocked parent",
|
|
status: "blocked",
|
|
});
|
|
const unassignedLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAU-2",
|
|
title: "Unassigned leaf",
|
|
status: "todo",
|
|
});
|
|
await block({ companyId, blockerIssueId: unassignedLeafId, blockedIssueId: unassignedParentId });
|
|
|
|
const assignedParentId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAU-3",
|
|
title: "Assigned blocked parent",
|
|
status: "blocked",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
const assignedLeafId = await insertIssue({
|
|
companyId,
|
|
identifier: "BAU-4",
|
|
title: "Unassigned leaf for assigned parent",
|
|
status: "todo",
|
|
});
|
|
await block({ companyId, blockerIssueId: assignedLeafId, blockedIssueId: assignedParentId });
|
|
|
|
const rows = await svc.list(companyId, { attention: "blocked", assigneeAgentId: agentId });
|
|
expect(rows.map((row) => row.id)).toEqual([assignedParentId]);
|
|
|
|
await expect(svc.count(companyId, { attention: "blocked", assigneeAgentId: agentId })).resolves.toBe(1);
|
|
});
|
|
|
|
it("rejects malformed assigneeAgentId filter values on the blocked-inbox path", async () => {
|
|
const { companyId } = await createCompany("BAM");
|
|
await expect(
|
|
svc.list(companyId, { attention: "blocked", assigneeAgentId: "not-a-uuid" }),
|
|
).rejects.toThrow(/assigneeAgentId/i);
|
|
await expect(
|
|
svc.count(companyId, { attention: "blocked", assigneeAgentId: "not-a-uuid" }),
|
|
).rejects.toThrow(/assigneeAgentId/i);
|
|
});
|
|
});
|