Files
PaperClipAI/server/src/services/native-runtime/native-skill-library-tools.integration.test.ts
T
Dotta 86bc3db693 feat(runner): search and load unassigned company skills (#19676)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Native agents use tools to read reusable company skills.
> - The existing native skill tools read only skills assigned to the
agent.
> - An agent can stop when a task needs another skill that is already in
the company library.
> - This pull request adds tools to search and read accessible company
skills on demand.
> - Agents can use the saved instructions without a persistent
assignment change.

## Linked Issues or Issue Description

**Problem or motivation**

An agent cannot use an unassigned company skill through the standard
native skill tools. A generic API workaround needs extra discovery and
can return the full library.

**Proposed solution**

Add `search_skills` and `load_skill` to the native tool catalog. Search
returns small pages of stored metadata. Load returns text from a saved
version and lists its files. Both tools use the current run identity and
existing company and project access checks.

**Alternatives considered**

Assign each skill before a read, or use generic API discovery. Both add
work to a read that the company already permits.

**Roadmap alignment**

This extends the existing skills discovery path. It does not add a
store, permission model or installation flow. Related: #15409 adds an
assigned-skill loader to a different adapter.

## What Changed

- Add bounded company skill search. Search does not synchronize sources
or fetch repositories.
- Add versioned text reads for SKILL.md and supporting files. Page text
and file lists. Reject unsafe paths and binary files.
- Recheck access after storage reads. Keep the existing closed Muse,
skill-test and completion-review tool scopes.
- Add integration tests with isolated PostgreSQL and real local package
storage. Update the native tool count assertion and skill documentation.
- Limit text files to 16 MiB before body reads. Accept saved file paths
up to 4,096 characters plus the repository prefix. Return the response
digest only on the first page.
- Add optional byte limits to the package readers. Select only the
requested legacy file in PostgreSQL. Cast the size comparison to
`bigint` so existing callers can omit the limit.
- Cache decoded text and its digest for one run. Limit the cache to 64
MiB and 64 files. Check access on each page and clear the cache when the
run closes.
- Read repository source files and wrapper inputs through verified warm
reads or isolated recovery. These reads do not hold the company startup
lock.

## Verification

- Local verification tested tree
`7ba5828387ca0a9c2ee99655818a28de1235a854`, published as commit
`c9d04cba601541cca506f5b72aa6f7272a25379f`. The published tree matches
that tested checkout. Current head
`33fa3d3d4c7988288685ce7c6499d064e0cb9079` (tree
`8daaa2f3264d1cd65a9b6d85dbb9d3729ac4a29d`) removes six comment lines
from three source files; its executable code is unchanged from the
locally tested revision.
- Four native skill and authority Vitest suites: 72 passed and 7
existing sandbox checks skipped. All 20 skill-library integration tests
passed.
- Skill-library and package-store suites: 65 passed. This includes the
45 package-store cases and the same 20 integration cases. Ran with umask
`022` for executable-file tests.
- Server source and test typecheck layers passed in low-memory mode. The
affected source cycle also passed a final separate check.
- `git diff --check` and `node scripts/check-module-boundaries.mjs`
passed.
- Red/green evidence: the new default inline-read case reproduced
PostgreSQL error `22003`. Two max-size paging cases reproduced extra
body reads. Warm and cold repository reads timed out while another
connection held the company startup lock. All five cases pass after the
fixes.
- Both 16 MiB paging cases check that the second page performs no
additional body read. They also check that source-access revocation
blocks a cached page. Warm and cold lock cases load both the generated
wrapper and a supporting file while the startup lock remains held.
- The first cold-read test attempt had an incorrect helper import.
Corrected the test import, reproduced the lock timeout, then verified
the fix.
- [CI on the previous
revision](https://github.com/paperclipai/paperclip/actions/runs/42319652795)
passed typecheck, build and policy. Serialized shard 2 failed in the
unchanged test `schedules bounded retries for failed accepted
interaction continuation wakes`. The same case passed locally: 1 passed;
416 cases were excluded by the filter. The cause of the earlier CI
failure remains unknown. [CI for
c9d04cba](https://github.com/paperclipai/paperclip/actions/runs/42323260426)
passed: 52 successful jobs and one skipped selector, including
typecheck, build, all serialized server shards, native server tests,
Runner/Rust, and e2e. This establishes a later pass; the earlier
heartbeat failure's cause remains unknown. [CI for current head
33fa3d3d](https://github.com/paperclipai/paperclip/actions/runs/42325148224)
passed: all 52 applicable workflow jobs succeeded, with one skipped
selector. The head has 58 successful check runs and three skipped
checks; Snyk also passed.
- Earlier failures remain recorded. Preflight cannot build Rust because
Cargo is absent. The first catalog assertion expected 51 tools instead
of 53. Test startup needed the plugin SDK build. An earlier typecheck
hit the 8 GiB memory limit; low-memory checks passed. The previous
package test failed under umask `077`; it passed under `022`, and this
run's complete package suite passes with `022`.
- Greptile reviewed current head `33fa3d3d` at 2026-11-07 01:40 UTC: 5/5
with no outstanding findings. The three older Ponytail threads are
resolved after checking the size/cache, long-path, and bigint fixes and
regression tests. Ponytail's supplemental refreshed assessment stopped
before completing and posted no new findings. Its earlier findings are
fixed and all seven review threads are resolved. The completed Greptile
assessment covers current head.
- No hosted deployment or live provider run was performed.

## Risks

- Package reads can recover stored packages through the existing storage
layer. Search reads only stored database metadata.
- Load is a read. It does not install files into the provider workspace
or change runtime bundles. It does not grant tool access or authorize
actions in the skill text.
- Callers must retain the returned version ID for later pages. A missing
version returns an error.
- Files above 16 MiB return a size-limit error. The run cache retains at
most 64 MiB of decoded text and 64 entries. A cache miss or eviction
requires a full verified file read. Each page still checks current
access. The SHA-256 response field is null after the first text or
file-list page.
- No database migration or UI change is required.

## Model Used

- OpenAI Codex, GPT-6 family, with reasoning, repository tools and code
execution. The exact model ID and context window are not exposed to this
agent.

## 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
- [x] I have run tests locally and they pass
- [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
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-07 09:23:14 -06:00

288 lines
20 KiB
TypeScript

import { createHash, randomUUID } from "node:crypto";
import { promises as fs } from "node:fs";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { eq } from "drizzle-orm";
import { agents, companies, companySkills, companySkillVersions, companySkillSources, heartbeatRuns, issues } from "@paperclipai/db";
import { startRecoveryPostgres } from "../../__tests__/helpers/recovery-postgres.js";
import { createDb } from "@paperclipai/db";
import { PaperclipRunnerToolAuthority } from "./paperclip-runner-tool-authority.js";
import { skillPackagePaths, skillPackageStore } from "../skill-package-store.js";
import { withSkillVersionCacheLock } from "../skill-version-cache.js";
import { getStorageService } from "../../storage/index.js";
describe("native company skill discovery", () => {
let temporary: Awaited<ReturnType<typeof startRecoveryPostgres>>;
let db: ReturnType<typeof createDb>;
let home: string;
beforeAll(async () => {
home = await mkdtemp(join(tmpdir(), "native-skill-library-"));
vi.stubEnv("PAPERCLIP_HOME", home);
vi.stubEnv("PAPERCLIP_STORAGE_PROVIDER", "local_disk");
vi.stubEnv("PAPERCLIP_STORAGE_LOCAL_DIR", join(home, "objects"));
temporary = await startRecoveryPostgres("native-skill-library-");
db = createDb(temporary.connectionString);
}, 60_000);
afterAll(async () => {
await temporary?.cleanup(); vi.unstubAllEnvs();
if (home) await rm(home, { recursive: true, force: true });
});
async function fixture() {
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), runId = randomUUID();
await db.insert(companies).values({ id: companyId, name: "Skill library", issuePrefix: `S${companyId.slice(0, 8)}` });
await db.insert(agents).values({ id: agentId, companyId, name: "Reviewer", adapterType: "paperclip_runner", status: "active", adapterConfig: { provider: "codex" } });
await db.insert(issues).values({ id: issueId, companyId, title: "Review", status: "in_progress", assigneeAgentId: agentId });
await db.insert(heartbeatRuns).values({ id: runId, companyId, agentId, nativeIssueId: issueId, status: "running", runtimeMode: "native", invocationSource: "assignment", triggerDetail: "system", contextSnapshot: { issueId, skillVersions: {} } });
await db.update(issues).set({ executionRunId: runId }).where(eq(issues.id, issueId));
const binding = { companyId, agentId, issueId, runId, apiToolsEnabled: false };
const authority = new PaperclipRunnerToolAuthority(db, binding);
const call = (tool: string, args: Record<string, unknown> = {}) => authority.execute({ tool, callId: randomUUID(), arguments: args });
return { ...binding, authority, call };
}
async function skill(companyId: string, key = "pr-merge-review", text = "Read the diff and check the tests.") {
const id = randomUUID(), versionId = randomUUID();
await db.insert(companySkills).values({ id, companyId, key, slug: key, name: key, description: "Review a pull request before merge", markdown: text, sourceType: "managed" });
await db.insert(companySkillVersions).values({ id: versionId, companyId, companySkillId: id, revisionNumber: 1, fileInventory: [
{ path: "SKILL.md", kind: "skill", content: text },
{ path: "references/checks.md", kind: "reference", content: "Check CI and the review result." },
{ path: "assets/icon.png", kind: "asset", content: "AAEC", encoding: "base64" },
] });
await db.update(companySkills).set({ currentVersionId: versionId }).where(eq(companySkills.id, id));
return { id, versionId, text };
}
it("finds and loads an unassigned skill without generic API tools or assignment changes", async () => {
const f = await fixture(), s = await skill(f.companyId);
expect(f.authority.definitions().map(t => t.name)).toEqual(expect.arrayContaining(["search_skills", "load_skill"]));
expect(await f.call("search_skills", { query: "MERGE" })).toMatchObject({ skills: [{ id: s.id, key: "pr-merge-review", versionId: s.versionId, trustLevel: "markdown_only" }], nextCursor: null });
expect(await f.call("load_skill", { skill: "pr-merge-review" })).toMatchObject({ skillId: s.id, versionId: s.versionId, path: "SKILL.md", text: s.text, nextOffset: null });
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path: "references/checks.md" })).toMatchObject({ text: "Check CI and the review result." });
expect((await db.select().from(agents).where(eq(agents.id, f.agentId)))[0]?.adapterConfig).toEqual({ provider: "codex" });
});
it("keeps default inline file reads compatible with existing callers", async () => {
const f = await fixture(), s = await skill(f.companyId);
const store = skillPackageStore(db);
const version = await store.version(f.companyId, s.id, s.versionId);
expect(version).toBeTruthy();
expect(await store.readVersionFile(version!, "SKILL.md")).toMatchObject({ content: s.text });
expect(await store.readVersionFile(version!, "references/checks.md", false))
.toMatchObject({ content: "Check CI and the review result." });
});
it("bounds and paginates search results and treats SQL wildcard characters literally", async () => {
const f = await fixture();
await skill(f.companyId, "review-a"); await skill(f.companyId, "review-b"); await skill(f.companyId, "review-c");
const first = await f.call("search_skills", { query: "review", limit: 2 }) as any;
const second = await f.call("search_skills", { query: "review", limit: 2, cursor: first.nextCursor }) as any;
expect(first.skills).toHaveLength(2); expect(second.skills).toHaveLength(1); expect(second.nextCursor).toBeNull();
expect(new Set([...first.skills, ...second.skills].map(s => s.id)).size).toBe(3);
expect(await f.call("search_skills", { query: "%" })).toMatchObject({ skills: [] });
});
it.each([false, true])("reads stored package bytes and supporting files (repository wrapper: %s)", async repository => {
const f = await fixture(), s = await skill(f.companyId);
const markdown = "---\nname: packaged-review\ndescription: Review packaged content.\n---\n\nUse [checks](references/checks.md).";
const root = repository ? "skills/review/" : "";
const packageId = await skillPackageStore(db).prepare(f.companyId, [
{ path: `${root}SKILL.md`, kind: "skill", content: markdown },
{ path: `${root}references/checks.md`, kind: "reference", content: "These bytes came from saved storage." },
]);
await db.update(companySkillVersions).set({ fileInventory: [], ...(repository
? { repositorySnapshotId: packageId, repositorySkillPath: `${root}SKILL.md` }
: { packageSnapshotId: packageId }) }).where(eq(companySkillVersions.id, s.versionId));
const first = await f.call("load_skill", { skill: s.id, versionId: s.versionId }) as any;
expect(first.text).toContain(repository ? ".paperclip-repository/skills/review/SKILL.md" : "Use [checks]");
const path = `${repository ? ".paperclip-repository/" : ""}${root}references/checks.md`;
expect(first.files).toContainEqual({ path, kind: "reference" });
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path })).toMatchObject({ text: "These bytes came from saved storage." });
expect(await f.authority.recover({ tool: "load_skill", callId: "recover-read", arguments: { skill: s.id, versionId: s.versionId, path } })).toMatchObject({ result: { text: "These bytes came from saved storage." } });
});
it("rechecks access after package storage I/O", async () => {
const f = await fixture(), s = await skill(f.companyId);
const packageId = await skillPackageStore(db).prepare(f.companyId, [{ path: "SKILL.md", kind: "skill", content: "Stored instructions" }]);
await db.update(companySkillVersions).set({ packageSnapshotId: packageId, fileInventory: [] }).where(eq(companySkillVersions.id, s.versionId));
const sourceId = randomUUID();
await db.insert(companySkillSources).values({ id: sourceId, companyId: f.companyId, repositoryUrl: "https://github.com/example/private", fullName: "example/private", trackingRef: "HEAD", accessScope: "projects" });
const storage = getStorageService(), read = storage.getObject.bind(storage);
const fault = vi.spyOn(storage, "getObject").mockImplementation(async (...args) => {
const result = await read(...args);
await db.update(companySkills).set({ accessSourceId: sourceId }).where(eq(companySkills.id, s.id));
return result;
});
try { await expect(f.call("load_skill", { skill: s.id })).rejects.toThrow("Skill not found"); }
finally { fault.mockRestore(); }
});
it.each([false, true])("reuses text between pages and still rechecks access (repository: %s)", async repository => {
const f = await fixture(), s = await skill(f.companyId);
const content = "x".repeat(16 * 1024 * 1024);
const packageId = await skillPackageStore(db).prepare(f.companyId, [
{ path: "SKILL.md", kind: "skill", content: "---\nname: review\ndescription: Review.\n---\n\nRead checks." },
{ path: "checks.md", kind: "reference", content },
]);
await db.update(companySkillVersions).set({ fileInventory: [], ...(repository
? { repositorySnapshotId: packageId, repositorySkillPath: "SKILL.md" }
: { packageSnapshotId: packageId }) }).where(eq(companySkillVersions.id, s.versionId));
const path = `${repository ? ".paperclip-repository/" : ""}checks.md`;
const open = vi.spyOn(fs, "open"), read = vi.spyOn(fs, "readFile");
const bodyReads = () => [...open.mock.calls, ...read.mock.calls].filter(args => String(args[0]).endsWith("/checks.md")).length;
try {
const first = await f.call("load_skill", { skill: s.id, path }) as any;
const reads = bodyReads();
expect(reads).toBeGreaterThan(0);
expect(first.byteSize).toBe(content.length);
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path, offset: first.nextOffset }))
.toMatchObject({ text: content.slice(6000, 12000), sha256: null });
expect(bodyReads()).toBe(reads);
const sourceId = randomUUID();
await db.insert(companySkillSources).values({ id: sourceId, companyId: f.companyId, repositoryUrl: "https://github.com/example/private", fullName: "example/private", trackingRef: "HEAD", accessScope: "projects" });
await db.update(companySkills).set({ accessSourceId: sourceId }).where(eq(companySkills.id, s.id));
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path, offset: 12000 }))
.toMatchObject({ outcome: "failed", code: "runner_skill_not_found" });
} finally { open.mockRestore(); read.mockRestore(); f.authority.close(); }
});
it.each([false, true])("reads repository files without waiting for the startup lock (cold: %s)", async cold => {
const f = await fixture(), s = await skill(f.companyId);
const store = skillPackageStore(db);
const packageId = await store.prepare(f.companyId, [
{ path: "SKILL.md", kind: "skill", content: "---\nname: review\ndescription: Review.\n---\n\nRead checks." },
{ path: "checks.md", kind: "reference", content: "Repository checks." },
]);
await db.update(companySkillVersions).set({ fileInventory: [], repositorySnapshotId: packageId, repositorySkillPath: "SKILL.md" })
.where(eq(companySkillVersions.id, s.versionId));
if (cold) {
await rm(skillPackagePaths(f.companyId, packageId).directory, { recursive: true, force: true });
}
let release!: () => void, acquired!: () => void;
const held = new Promise<void>(resolve => { release = resolve; });
const ready = new Promise<void>(resolve => { acquired = resolve; });
const lock = withSkillVersionCacheLock(db, f.companyId, async () => { acquired(); await held; });
await ready;
let timeout: ReturnType<typeof setTimeout> | undefined;
try {
await Promise.race([
(async () => {
expect(await f.call("load_skill", { skill: s.id })).toMatchObject({ path: "SKILL.md" });
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path: ".paperclip-repository/checks.md" }))
.toMatchObject({ text: "Repository checks." });
})(),
new Promise((_, reject) => { timeout = setTimeout(() => reject(new Error("Skill read waited for the startup lock")), 3000); }),
]);
} finally { clearTimeout(timeout); release(); await lock; f.authority.close(); }
});
it.each(["inline", "package", "repository"])("rejects oversized text before reading its body (%s)", async storage => {
const f = await fixture(), s = await skill(f.companyId);
const root = storage === "repository" ? "skills/review/" : "";
const files = [
{ path: `${root}SKILL.md`, kind: "skill" as const, content: "---\nname: review\ndescription: Review.\n---\n\nRead references." },
{ path: `${root}references/oversized.md`, kind: "reference" as const, content: "x".repeat(16 * 1024 * 1024 + 1) },
];
if (storage === "inline") {
await db.update(companySkillVersions).set({ fileInventory: files }).where(eq(companySkillVersions.id, s.versionId));
} else {
const packageId = await skillPackageStore(db).prepare(f.companyId, files);
await db.update(companySkillVersions).set({ fileInventory: [], ...(storage === "repository"
? { repositorySnapshotId: packageId, repositorySkillPath: `${root}SKILL.md` }
: { packageSnapshotId: packageId }) }).where(eq(companySkillVersions.id, s.versionId));
}
const open = vi.spyOn(fs, "open"), read = vi.spyOn(fs, "readFile");
try {
const path = `${storage === "repository" ? ".paperclip-repository/" : ""}${root}references/oversized.md`;
for (const offset of [0, 6000]) {
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path, offset }))
.toMatchObject({ outcome: "failed", code: "runner_skill_file_size_limit" });
}
expect([...open.mock.calls, ...read.mock.calls].some(args => String(args[0]).endsWith("oversized.md"))).toBe(false);
} finally { open.mockRestore(); read.mockRestore(); }
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId })).toMatchObject({ path: "SKILL.md" });
});
it.each([false, true])("loads long supporting paths from the returned inventory (repository wrapper: %s)", async repository => {
const f = await fixture(), s = await skill(f.companyId);
const root = repository ? "skills/review/" : "";
const path = `${root}${("nested-" + "x".repeat(90) + "/").repeat(12)}checks.md`;
const packageId = await skillPackageStore(db).prepare(f.companyId, [
{ path: `${root}SKILL.md`, kind: "skill", content: "---\nname: review\ndescription: Review.\n---\n\nRead checks." },
{ path, kind: "reference", content: "Long paths remain readable." },
]);
await db.update(companySkillVersions).set({ fileInventory: [], ...(repository
? { repositorySnapshotId: packageId, repositorySkillPath: `${root}SKILL.md` }
: { packageSnapshotId: packageId }) }).where(eq(companySkillVersions.id, s.versionId));
const first = await f.call("load_skill", { skill: s.id, versionId: s.versionId }) as any;
const listedPath = first.files.find((file: { path: string; kind: string }) => file.kind === "reference").path;
expect(listedPath.length).toBeGreaterThan(1000);
expect(await f.call("load_skill", { skill: s.id, versionId: s.versionId, path: listedPath }))
.toMatchObject({ text: "Long paths remain readable." });
});
it("pages the file inventory without repeating the response digest", async () => {
const f = await fixture(), s = await skill(f.companyId);
await db.update(companySkillVersions).set({ fileInventory: [
{ path: "SKILL.md", kind: "skill", content: s.text },
...Array.from({ length: 50 }, (_, index) => ({ path: `references/${index}.md`, kind: "reference" as const, content: "Check." })),
] }).where(eq(companySkillVersions.id, s.versionId));
const first = await f.call("load_skill", { skill: s.id }) as any;
expect(first.files).toHaveLength(50);
expect(first.nextFileOffset).toBe(50);
const second = await f.call("load_skill", { skill: s.id, versionId: first.versionId, fileOffset: first.nextFileOffset }) as any;
expect(second.files).toHaveLength(1);
expect(second.nextFileOffset).toBeNull();
expect(second.sha256).toBeNull();
});
it("keeps pages and reference reads on the selected immutable version", async () => {
const f = await fixture(), s = await skill(f.companyId, "long-review", "a".repeat(5999) + "🚀" + "b".repeat(2000));
const first = await f.call("load_skill", { skill: s.id }) as any;
expect(first.text.length).toBeLessThanOrEqual(6000);
expect(first.sha256).toBe(createHash("sha256").update(s.text).digest("hex"));
const changed = randomUUID();
await db.insert(companySkillVersions).values({ id: changed, companyId: f.companyId, companySkillId: s.id, revisionNumber: 2, fileInventory: [{ path: "SKILL.md", kind: "skill", content: "New version" }] });
await db.update(companySkills).set({ currentVersionId: changed }).where(eq(companySkills.id, s.id));
const second = await f.call("load_skill", { skill: s.id, versionId: first.versionId, offset: first.nextOffset }) as any;
expect(first.text + second.text).toBe(s.text);
expect(second.sha256).toBeNull();
expect(await f.call("load_skill", { skill: s.id, offset: first.nextOffset })).toMatchObject({ outcome: "failed", code: "runner_skill_invalid_arguments" });
});
it("hides foreign and project-restricted skills, including after access changes", async () => {
const a = await fixture(), b = await fixture(), s = await skill(a.companyId), foreign = await skill(b.companyId);
expect(await a.call("load_skill", { skill: foreign.id })).toMatchObject({ outcome: "failed", code: "runner_skill_not_found" });
expect(await a.call("load_skill", { skill: s.id, versionId: foreign.versionId })).toMatchObject({ outcome: "failed", code: "runner_skill_version_not_found" });
const sourceId = randomUUID();
await db.insert(companySkillSources).values({ id: sourceId, companyId: a.companyId, repositoryUrl: "https://github.com/example/private", fullName: "example/private", trackingRef: "HEAD", accessScope: "projects" });
await db.update(companySkills).set({ accessSourceId: sourceId }).where(eq(companySkills.id, s.id));
expect(await a.call("search_skills", { query: "review" })).toMatchObject({ skills: [] });
expect(await a.call("load_skill", { skill: s.id })).toMatchObject({ outcome: "failed", code: "runner_skill_not_found" });
});
it("rejects invalid paths, binary files, and stale run authority", async () => {
const f = await fixture(), s = await skill(f.companyId);
for (const path of ["../SKILL.md", "/etc/passwd", "references\\checks.md"]) {
expect(await f.call("load_skill", { skill: s.id, path })).toMatchObject({ outcome: "failed", code: "runner_skill_invalid_arguments" });
}
expect(await f.call("load_skill", { skill: s.id, path: "assets/icon.png" })).toMatchObject({ outcome: "failed", code: "runner_skill_binary_file" });
expect(await f.call("load_skill", { skill: s.id, path: "missing.md" })).toMatchObject({ outcome: "failed", code: "runner_skill_file_not_found" });
await db.update(heartbeatRuns).set({ status: "failed" }).where(eq(heartbeatRuns.id, f.runId));
await expect(f.call("search_skills", {})).rejects.toThrow();
});
it("preserves the closed Muse, skill-test and completion-review profiles", async () => {
const f = await fixture();
for (const extra of [{ museRuntime: true }, { workMode: "skill_test" as const }, { nativeReview: {} as any }]) {
const names = new PaperclipRunnerToolAuthority(db, { ...f, ...extra }).definitions().map(t => t.name);
expect(names).not.toContain("search_skills"); expect(names).not.toContain("load_skill");
}
for (const workMode of ["ask", "planning"] as const) {
expect(new PaperclipRunnerToolAuthority(db, { ...f, workMode }).definitions().map(t => t.name)).toEqual(expect.arrayContaining(["search_skills", "load_skill"]));
}
});
});