@indigoai-us/hq-cli 5.77.13 → 5.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/assets/scaffold/core/scripts/archive-old-threads.sh +86 -0
- package/assets/scaffold/core/scripts/backfill-company-skill-mirrors.sh +73 -0
- package/assets/scaffold/core/scripts/backfill-workspace-mirror.sh +51 -0
- package/assets/scaffold/core/scripts/codex-skill-bridge.sh +550 -0
- package/assets/scaffold/core/scripts/detect-stale-core-policy-mirror.sh +185 -0
- package/assets/scaffold/core/scripts/hq-status-summary.sh +187 -0
- package/assets/scaffold/core/scripts/ontology-readme-drift.sh +264 -0
- package/assets/scaffold/core/scripts/qmd-reindex-after-sync.sh +93 -0
- package/assets/scaffold/core/scripts/rebuild-all-indexes.sh +69 -0
- package/assets/scaffold/core/scripts/rebuild-companies-index.sh +206 -0
- package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +127 -0
- package/assets/scaffold/core/scripts/rebuild-orchestrator-index.sh +86 -0
- package/assets/scaffold/core/scripts/rebuild-projects-index.sh +105 -0
- package/assets/scaffold/core/scripts/rebuild-public-knowledge-index.sh +83 -0
- package/assets/scaffold/core/scripts/rebuild-reports-index.sh +114 -0
- package/assets/scaffold/core/scripts/rebuild-social-drafts-index.sh +135 -0
- package/assets/scaffold/core/scripts/rebuild-threads-index.sh +82 -0
- package/assets/scaffold/core/scripts/rebuild-workers-index.sh +97 -0
- package/assets/scaffold/core/scripts/resize-screenshot.sh +47 -0
- package/assets/scaffold/core/scripts/token-usage-report.sh +254 -0
- package/assets/scaffold/core/scripts/worktree.sh +136 -0
- package/dist/commands/agents.js +28 -12
- package/dist/commands/api-keys.js +100 -20
- package/dist/commands/core.d.ts +90 -0
- package/dist/commands/core.js +279 -0
- package/dist/commands/files-browse.d.ts +21 -0
- package/dist/commands/files-browse.js +145 -24
- package/dist/commands/files.js +33 -7
- package/dist/commands/members.js +16 -5
- package/dist/commands/pack-install.d.ts +14 -0
- package/dist/commands/pack-install.js +51 -2
- package/dist/commands/pkg-install.js +43 -0
- package/dist/commands/run.js +8 -0
- package/dist/commands/secrets.js +125 -65
- package/dist/main.js +6 -0
- package/dist/utils/api-key-command-gate.d.ts +45 -0
- package/dist/utils/api-key-command-gate.js +51 -0
- package/dist/utils/hq-roots.d.ts +91 -0
- package/dist/utils/hq-roots.js +212 -0
- package/dist/utils/resolve-vault-credential.d.ts +63 -3
- package/dist/utils/resolve-vault-credential.js +152 -6
- package/dist/utils/run-bundled-script.d.ts +66 -0
- package/dist/utils/run-bundled-script.js +80 -0
- package/dist/utils/vault-api.d.ts +21 -0
- package/dist/utils/vault-api.js +74 -3
- package/package.json +7 -1
- package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
- package/.github/workflows/ci.yml +0 -46
- package/.github/workflows/publish.yml +0 -36
- package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
- package/e2e/cli.test.ts +0 -128
- package/eslint.config.js +0 -37
- package/pnpm-workspace.yaml +0 -4
- package/scripts/chmod-bins.mjs +0 -49
- package/scripts/generate-dsn.mjs +0 -26
- package/scripts/generate-scan-packages-table.mjs +0 -113
- package/scripts/smoke-sources-signals.sh +0 -103
- package/src/bin/hq-auth-refresh.ts +0 -43
- package/src/cli-version.ts +0 -13
- package/src/commands/__fixtures__/make-tar.ts +0 -126
- package/src/commands/_patterns.ts +0 -10
- package/src/commands/add.ts +0 -75
- package/src/commands/agents.test.ts +0 -527
- package/src/commands/agents.ts +0 -923
- package/src/commands/api-keys.test.ts +0 -291
- package/src/commands/api-keys.ts +0 -382
- package/src/commands/artifact-verify.test.ts +0 -177
- package/src/commands/auth.test.ts +0 -82
- package/src/commands/auth.ts +0 -213
- package/src/commands/billing.test.ts +0 -158
- package/src/commands/billing.ts +0 -146
- package/src/commands/channels.test.ts +0 -74
- package/src/commands/channels.ts +0 -91
- package/src/commands/cloud-demote.test.ts +0 -401
- package/src/commands/cloud-demote.ts +0 -278
- package/src/commands/cloud-provision.test.ts +0 -1117
- package/src/commands/cloud-provision.ts +0 -942
- package/src/commands/cloud.pull-all.test.ts +0 -711
- package/src/commands/cloud.pull-per-company.test.ts +0 -188
- package/src/commands/cloud.push-all.test.ts +0 -485
- package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
- package/src/commands/cloud.selectors.test.ts +0 -208
- package/src/commands/cloud.status.test.ts +0 -160
- package/src/commands/cloud.test.ts +0 -41
- package/src/commands/cloud.ts +0 -2130
- package/src/commands/company.test.ts +0 -202
- package/src/commands/company.ts +0 -148
- package/src/commands/creators.test.ts +0 -60
- package/src/commands/creators.ts +0 -117
- package/src/commands/crm.test.ts +0 -179
- package/src/commands/crm.ts +0 -236
- package/src/commands/db-migrate.ts +0 -55
- package/src/commands/db-provision.ts +0 -114
- package/src/commands/db-sql.ts +0 -124
- package/src/commands/db-status.ts +0 -108
- package/src/commands/db.ts +0 -26
- package/src/commands/dm.test.ts +0 -748
- package/src/commands/dm.ts +0 -1226
- package/src/commands/feedback.test.ts +0 -413
- package/src/commands/feedback.ts +0 -169
- package/src/commands/files-browse.test.ts +0 -1249
- package/src/commands/files-browse.ts +0 -1506
- package/src/commands/files-delete.test.ts +0 -484
- package/src/commands/files-recovery.test.ts +0 -370
- package/src/commands/files.test.ts +0 -722
- package/src/commands/files.ts +0 -1446
- package/src/commands/group-grants.test.ts +0 -330
- package/src/commands/group-grants.ts +0 -455
- package/src/commands/groups.test.ts +0 -44
- package/src/commands/groups.ts +0 -368
- package/src/commands/integrations.test.ts +0 -633
- package/src/commands/integrations.ts +0 -507
- package/src/commands/list.ts +0 -85
- package/src/commands/login.ts +0 -52
- package/src/commands/logout.ts +0 -30
- package/src/commands/marketplace-install.test.ts +0 -543
- package/src/commands/marketplace-security.test.ts +0 -646
- package/src/commands/mcp-registration.test.ts +0 -2787
- package/src/commands/mcp-registration.ts +0 -2612
- package/src/commands/mcp-status.test.ts +0 -483
- package/src/commands/mcp-status.ts +0 -575
- package/src/commands/mcp-status.us011.test.ts +0 -243
- package/src/commands/meetings.test.ts +0 -522
- package/src/commands/meetings.ts +0 -789
- package/src/commands/members.test.ts +0 -1474
- package/src/commands/members.ts +0 -1181
- package/src/commands/onboard-identity-guard.test.ts +0 -99
- package/src/commands/onboard-identity-guard.ts +0 -103
- package/src/commands/onboard-join.test.ts +0 -96
- package/src/commands/onboard-join.ts +0 -101
- package/src/commands/onboard-warning.test.ts +0 -26
- package/src/commands/onboard-warning.ts +0 -12
- package/src/commands/onboard.ts +0 -267
- package/src/commands/outposts-heartbeat.test.ts +0 -299
- package/src/commands/outposts-heartbeat.ts +0 -310
- package/src/commands/outposts-replica-sync.test.ts +0 -272
- package/src/commands/outposts-self-deploy.test.ts +0 -243
- package/src/commands/outposts.test.ts +0 -1039
- package/src/commands/outposts.ts +0 -1935
- package/src/commands/pack-install-secret-authorization.test.ts +0 -115
- package/src/commands/pack-install.test.ts +0 -1469
- package/src/commands/pack-install.ts +0 -2247
- package/src/commands/pack-update-cache.test.ts +0 -149
- package/src/commands/packs.test.ts +0 -88
- package/src/commands/packs.ts +0 -622
- package/src/commands/people.test.ts +0 -807
- package/src/commands/people.ts +0 -422
- package/src/commands/pkg-install.dispatch.test.ts +0 -71
- package/src/commands/pkg-install.ts +0 -215
- package/src/commands/pkg-list.test.ts +0 -79
- package/src/commands/pkg-list.ts +0 -13
- package/src/commands/pkg-remove.ts +0 -71
- package/src/commands/pkg-update.ts +0 -189
- package/src/commands/publish.test.ts +0 -650
- package/src/commands/publish.ts +0 -580
- package/src/commands/reindex.test.ts +0 -259
- package/src/commands/reindex.ts +0 -274
- package/src/commands/rescue.test.ts +0 -39
- package/src/commands/rescue.ts +0 -210
- package/src/commands/run.env-local.test.ts +0 -88
- package/src/commands/run.test.ts +0 -45
- package/src/commands/run.ts +0 -184
- package/src/commands/safe-extract.test.ts +0 -459
- package/src/commands/safe-extract.ts +0 -444
- package/src/commands/secrets-scope.test.ts +0 -56
- package/src/commands/secrets-scope.ts +0 -32
- package/src/commands/secrets.parse-destination.test.ts +0 -38
- package/src/commands/secrets.test.ts +0 -2037
- package/src/commands/secrets.ts +0 -2240
- package/src/commands/signals.ts +0 -351
- package/src/commands/skill.test.ts +0 -770
- package/src/commands/skill.ts +0 -796
- package/src/commands/sources.ts +0 -362
- package/src/commands/sync-mode.test.ts +0 -366
- package/src/commands/sync-mode.ts +0 -387
- package/src/commands/sync-narrow.test.ts +0 -633
- package/src/commands/sync-narrow.ts +0 -555
- package/src/commands/sync.ts +0 -165
- package/src/commands/team-sync.ts +0 -628
- package/src/commands/update.ts +0 -71
- package/src/commands/whoami.ts +0 -83
- package/src/commands/workers.test.ts +0 -158
- package/src/commands/workers.ts +0 -301
- package/src/index.test.ts +0 -32
- package/src/index.ts +0 -20
- package/src/lib/db/control-plane.test.ts +0 -59
- package/src/lib/db/control-plane.ts +0 -113
- package/src/lib/db/local.test.ts +0 -81
- package/src/lib/db/local.ts +0 -148
- package/src/lib/db/migrate.test.ts +0 -133
- package/src/lib/db/migrate.ts +0 -137
- package/src/lib/db/paths.test.ts +0 -112
- package/src/lib/db/paths.ts +0 -128
- package/src/lib/db/remote-engine.test.ts +0 -44
- package/src/lib/db/remote-engine.ts +0 -148
- package/src/lib/db/remote-sql.test.ts +0 -32
- package/src/lib/db/remote-sql.ts +0 -62
- package/src/lib/db/sql.test.ts +0 -106
- package/src/lib/db/sql.ts +0 -192
- package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
- package/src/lib/local-tree-diff.test.ts +0 -301
- package/src/lib/local-tree-diff.ts +0 -362
- package/src/lib/narrow-hint-banner.test.ts +0 -235
- package/src/lib/narrow-hint-banner.ts +0 -212
- package/src/lib/plan-limit-nag.test.ts +0 -317
- package/src/lib/plan-limit-nag.ts +0 -264
- package/src/main.ts +0 -371
- package/src/node-preflight.test.ts +0 -60
- package/src/node-preflight.ts +0 -67
- package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
- package/src/outpost/session-heartbeat-guard.test.ts +0 -105
- package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
- package/src/outpost/session-heartbeat-publisher.ts +0 -186
- package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
- package/src/outpost/session-heartbeat.test.ts +0 -459
- package/src/outpost/session-heartbeat.ts +0 -877
- package/src/packaging.test.ts +0 -109
- package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
- package/src/run/discover-schemas.test.ts +0 -153
- package/src/run/discover-schemas.ts +0 -79
- package/src/run/hq-plugin.test.ts +0 -371
- package/src/run/hq-plugin.ts +0 -277
- package/src/run/varlock-shape.test.ts +0 -57
- package/src/schemas/hq-package.schema.json +0 -155
- package/src/sentry-before-send.test.ts +0 -359
- package/src/sentry-before-send.ts +0 -221
- package/src/sentry-epipe.test.ts +0 -37
- package/src/sentry-release.test.ts +0 -54
- package/src/sentry.test.ts +0 -24
- package/src/sentry.ts +0 -54
- package/src/strategies/link.ts +0 -62
- package/src/strategies/merge.ts +0 -142
- package/src/types.ts +0 -146
- package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
- package/src/utils/auth-error.test.ts +0 -40
- package/src/utils/auth-error.ts +0 -42
- package/src/utils/billing-gate.test.ts +0 -95
- package/src/utils/billing-gate.ts +0 -228
- package/src/utils/breadcrumb-buffer.ts +0 -18
- package/src/utils/cli-telemetry.test.ts +0 -153
- package/src/utils/cli-telemetry.ts +0 -61
- package/src/utils/cognito-session.machine.test.ts +0 -109
- package/src/utils/cognito-session.refresh.test.ts +0 -84
- package/src/utils/cognito-session.test.ts +0 -328
- package/src/utils/cognito-session.ts +0 -448
- package/src/utils/company-selection-error.test.ts +0 -42
- package/src/utils/company-selection-error.ts +0 -45
- package/src/utils/contribution-table.ts +0 -83
- package/src/utils/environmental-error.test.ts +0 -45
- package/src/utils/environmental-error.ts +0 -39
- package/src/utils/epipe.test.ts +0 -28
- package/src/utils/epipe.ts +0 -29
- package/src/utils/expected-cli-error.test.ts +0 -28
- package/src/utils/expected-cli-error.ts +0 -39
- package/src/utils/feedback-diagnostics.test.ts +0 -183
- package/src/utils/feedback-diagnostics.ts +0 -123
- package/src/utils/feedback-screenshots.test.ts +0 -134
- package/src/utils/feedback-screenshots.ts +0 -124
- package/src/utils/feedback-versions.test.ts +0 -98
- package/src/utils/feedback-versions.ts +0 -68
- package/src/utils/git.ts +0 -74
- package/src/utils/integrity.ts +0 -59
- package/src/utils/intercepted-process-exit.test.ts +0 -37
- package/src/utils/intercepted-process-exit.ts +0 -36
- package/src/utils/login-provider.test.ts +0 -42
- package/src/utils/login-provider.ts +0 -30
- package/src/utils/manifest.test.ts +0 -167
- package/src/utils/manifest.ts +0 -131
- package/src/utils/pack-contributions.test.ts +0 -603
- package/src/utils/pack-contributions.ts +0 -450
- package/src/utils/people.ts +0 -215
- package/src/utils/registry-client.ts +0 -204
- package/src/utils/registry.ts +0 -90
- package/src/utils/resolve-vault-credential.test.ts +0 -69
- package/src/utils/resolve-vault-credential.ts +0 -60
- package/src/utils/sandbox-runner-client.test.ts +0 -279
- package/src/utils/sandbox-runner-client.ts +0 -260
- package/src/utils/secrets-cache.ts +0 -183
- package/src/utils/sentry-identity.ts +0 -45
- package/src/utils/settle-with-timeout.test.ts +0 -21
- package/src/utils/settle-with-timeout.ts +0 -22
- package/src/utils/user-yaml-error.test.ts +0 -24
- package/src/utils/user-yaml-error.ts +0 -30
- package/src/utils/vault-api.test.ts +0 -536
- package/src/utils/vault-api.ts +0 -382
- package/src/utils/version-check.test.ts +0 -176
- package/src/utils/version-check.ts +0 -155
- package/src/utils/version-gate.test.ts +0 -1024
- package/src/utils/version-gate.ts +0 -702
- package/test/commands/db-tenant-isolation.test.ts +0 -94
- package/test/commands/db.test.ts +0 -85
- package/test/commands/signals.test.ts +0 -207
- package/test/commands/sources.test.ts +0 -231
- package/test/e2e/smoke-install-mcp.sh +0 -113
- package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
- package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
- package/test/fixtures/signals/action_item/sample.md +0 -16
- package/test/fixtures/signals/summary/sample.md +0 -12
- package/test/fixtures/sources/meetings/sample.md +0 -25
- package/test/helpers/cli-runner.ts +0 -150
- package/test/helpers/s3-list-mock.ts +0 -79
- package/test/helpers/vault-service-mock.ts +0 -295
- package/test/sources-signals/smoke.test.ts +0 -228
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -11
- package/vitest.e2e.config.ts +0 -7
|
@@ -1,770 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit + story tests for `hq skill` (skill.ts) — US-017.
|
|
3
|
-
*
|
|
4
|
-
* Story tests (PRD):
|
|
5
|
-
* - Given local edits to a skill, `hq skill suggest --diff` creates a
|
|
6
|
-
* suggestion the owner's inbox renders WITH a diff.
|
|
7
|
-
* - Given a pending suggestion, `hq skill review --accept` merges and closes it.
|
|
8
|
-
*
|
|
9
|
-
* Plus AC coverage: the CLI reuses the SAME wired hq-pro routes (exact paths
|
|
10
|
-
* asserted, AC2); a suggest never runs a client-side lock/permission pre-check
|
|
11
|
-
* (AC3); an author note rides as `authorNote` and attribution is the server-
|
|
12
|
-
* derived identity (AC4); the base-changed accept conflict is surfaced with
|
|
13
|
-
* acknowledgement guidance (US-009).
|
|
14
|
-
*
|
|
15
|
-
* The network is exercised through the REAL `vaultApiFetch` over a spied global
|
|
16
|
-
* `fetch` (so the actual route URLs are asserted). The git-diff base is an
|
|
17
|
-
* injected seam so no real repo is needed.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import * as fs from "node:fs";
|
|
21
|
-
import * as os from "node:os";
|
|
22
|
-
import * as path from "node:path";
|
|
23
|
-
import {
|
|
24
|
-
afterEach,
|
|
25
|
-
beforeAll,
|
|
26
|
-
beforeEach,
|
|
27
|
-
describe,
|
|
28
|
-
expect,
|
|
29
|
-
it,
|
|
30
|
-
vi,
|
|
31
|
-
type MockInstance,
|
|
32
|
-
} from "vitest";
|
|
33
|
-
|
|
34
|
-
// Stub the Cognito token so the action runs without keychain/disk I/O.
|
|
35
|
-
vi.mock("../utils/cognito-session.js", async (importOriginal) => {
|
|
36
|
-
const original = (await importOriginal()) as Record<string, unknown>;
|
|
37
|
-
return {
|
|
38
|
-
...original,
|
|
39
|
-
ensureCognitoToken: vi.fn(async () => "test-token"),
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
import { Command } from "commander";
|
|
44
|
-
import chalk from "chalk";
|
|
45
|
-
import {
|
|
46
|
-
registerSkillCommand,
|
|
47
|
-
parseSkillUid,
|
|
48
|
-
sha256Hex,
|
|
49
|
-
buildSuggestionCreateBody,
|
|
50
|
-
mapSkillError,
|
|
51
|
-
resolveCompanySlug,
|
|
52
|
-
resolveSkillTarget,
|
|
53
|
-
findSkillFileByUid,
|
|
54
|
-
formatSuggestionsList,
|
|
55
|
-
type GitBaseReader,
|
|
56
|
-
type SuggestionRow,
|
|
57
|
-
} from "./skill.js";
|
|
58
|
-
|
|
59
|
-
// Plain (un-coloured) rendered text so assertions read the literal output.
|
|
60
|
-
beforeAll(() => {
|
|
61
|
-
chalk.level = 0;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
function jsonResponse(body: unknown, status = 200): Response {
|
|
65
|
-
return new Response(JSON.stringify(body), {
|
|
66
|
-
status,
|
|
67
|
-
headers: { "Content-Type": "application/json" },
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let fetchSpy: MockInstance<typeof fetch>;
|
|
72
|
-
let exitSpy: MockInstance<typeof process.exit>;
|
|
73
|
-
let logSpy: MockInstance<typeof console.log>;
|
|
74
|
-
let errSpy: MockInstance<typeof console.error>;
|
|
75
|
-
const tmpDirs: string[] = [];
|
|
76
|
-
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
fetchSpy = vi.spyOn(globalThis, "fetch");
|
|
79
|
-
exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
|
80
|
-
throw new Error(`__EXIT__:${code ?? 0}`);
|
|
81
|
-
}) as never);
|
|
82
|
-
logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
83
|
-
errSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
afterEach(() => {
|
|
87
|
-
vi.restoreAllMocks();
|
|
88
|
-
while (tmpDirs.length > 0) {
|
|
89
|
-
const dir = tmpDirs.pop()!;
|
|
90
|
-
try {
|
|
91
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
92
|
-
} catch {
|
|
93
|
-
/* best effort */
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
/** A commander program with the skill command registered + a git-base seam. */
|
|
99
|
-
function buildProgram(deps: { gitBase?: GitBaseReader } = {}): Command {
|
|
100
|
-
const program = new Command();
|
|
101
|
-
program.configureOutput({ writeOut: () => undefined, writeErr: () => undefined });
|
|
102
|
-
registerSkillCommand(program, deps);
|
|
103
|
-
return program;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Make a temp dir holding a SKILL.md with `skill_uid` frontmatter + body. */
|
|
107
|
-
function makeSkillDir(uid: string, body: string): string {
|
|
108
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-skill-"));
|
|
109
|
-
tmpDirs.push(dir);
|
|
110
|
-
fs.writeFileSync(
|
|
111
|
-
path.join(dir, "SKILL.md"),
|
|
112
|
-
`---\nskill_uid: ${uid}\nname: Test Skill\n---\n${body}`,
|
|
113
|
-
);
|
|
114
|
-
return dir;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function joinedLog(): string {
|
|
118
|
-
return logSpy.mock.calls.map((c) => String(c[0])).join("\n");
|
|
119
|
-
}
|
|
120
|
-
function joinedErr(): string {
|
|
121
|
-
// Join every arg of each call — some error paths log `console.error("Error:", msg)`.
|
|
122
|
-
return errSpy.mock.calls.map((c) => c.map((a) => String(a)).join(" ")).join("\n");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const UID = "skl_01ABCDEFGHJKMNPQRSTVWXYZ00";
|
|
126
|
-
|
|
127
|
-
// ===========================================================================
|
|
128
|
-
// Story tests
|
|
129
|
-
// ===========================================================================
|
|
130
|
-
|
|
131
|
-
describe("story: suggest --diff → suggestion in the owner's inbox with a diff", () => {
|
|
132
|
-
it("posts proposed + base to the CREATE route and the inbox renders the diff", async () => {
|
|
133
|
-
const dir = makeSkillDir(UID, "# Title\n\nfixed line\n");
|
|
134
|
-
const proposed = fs.readFileSync(path.join(dir, "SKILL.md"), "utf-8");
|
|
135
|
-
const base = proposed.replace("fixed line", "old line");
|
|
136
|
-
const gitBase: GitBaseReader = vi.fn(async () => base);
|
|
137
|
-
|
|
138
|
-
// CREATE response (server derived the diff from baseContent).
|
|
139
|
-
fetchSpy.mockResolvedValueOnce(
|
|
140
|
-
jsonResponse({
|
|
141
|
-
ok: true,
|
|
142
|
-
created: true,
|
|
143
|
-
company: "acme",
|
|
144
|
-
skillUid: UID,
|
|
145
|
-
suggestionId: "sgn_1",
|
|
146
|
-
status: "open",
|
|
147
|
-
authorPersonUid: "prs_me",
|
|
148
|
-
payloadFormat: "diff",
|
|
149
|
-
baseContentHash: "hhh",
|
|
150
|
-
authorNote: "fix the thing",
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
await buildProgram({ gitBase }).parseAsync(
|
|
155
|
-
["skill", "--company", "acme", "suggest", dir, "--diff", "--note", "fix the thing"],
|
|
156
|
-
{ from: "user" },
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// AC2: the exact wired CREATE route + a diff-capable body (proposed + base).
|
|
160
|
-
const createCall = fetchSpy.mock.calls[0];
|
|
161
|
-
expect(String(createCall[0])).toMatch(
|
|
162
|
-
/\/v1\/files\/skills\/company\/acme\/skl_01ABCDEFGHJKMNPQRSTVWXYZ00\/suggestions$/,
|
|
163
|
-
);
|
|
164
|
-
expect(createCall[1]?.method).toBe("POST");
|
|
165
|
-
const body = JSON.parse((createCall[1]?.body as string) ?? "{}");
|
|
166
|
-
expect(body.proposedContent).toBe(proposed);
|
|
167
|
-
expect(body.baseContent).toBe(base);
|
|
168
|
-
expect(body.authorNote).toBe("fix the thing"); // AC4 author note
|
|
169
|
-
expect(body.baseContentHash).toBeUndefined(); // server derives it from baseContent
|
|
170
|
-
|
|
171
|
-
// AC4: attribution is the server-derived identity, surfaced to the user.
|
|
172
|
-
expect(joinedLog()).toContain("prs_me");
|
|
173
|
-
expect(joinedLog()).toContain("sgn_1");
|
|
174
|
-
|
|
175
|
-
// Now the owner's inbox lists it WITH a diff.
|
|
176
|
-
logSpy.mockClear();
|
|
177
|
-
fetchSpy.mockResolvedValueOnce(
|
|
178
|
-
jsonResponse({
|
|
179
|
-
suggestions: [
|
|
180
|
-
{
|
|
181
|
-
suggestionId: "sgn_1",
|
|
182
|
-
skillUid: UID,
|
|
183
|
-
authorPersonUid: "prs_me",
|
|
184
|
-
status: "open",
|
|
185
|
-
baseChanged: false,
|
|
186
|
-
presentation: "diff",
|
|
187
|
-
unifiedDiff:
|
|
188
|
-
"--- a/SKILL.md\n+++ b/SKILL.md\n@@ -3 +3 @@\n-old line\n+fixed line\n",
|
|
189
|
-
fullContent: proposed,
|
|
190
|
-
authorNote: "fix the thing",
|
|
191
|
-
createdAt: "2026-07-09T00:00:00Z",
|
|
192
|
-
path: "skills/test-skill/SKILL.md",
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
count: 1,
|
|
196
|
-
}),
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
await buildProgram().parseAsync(
|
|
200
|
-
["skill", "--company", "acme", "list-suggestions", "--show-diff"],
|
|
201
|
-
{ from: "user" },
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
const inbox = joinedLog();
|
|
205
|
-
expect(inbox).toContain("sgn_1");
|
|
206
|
-
expect(inbox).toContain("-old line");
|
|
207
|
-
expect(inbox).toContain("+fixed line");
|
|
208
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe("story: review --accept merges and closes a pending suggestion", () => {
|
|
213
|
-
it("resolves the row via LIST then POSTs {path} to the ACCEPT route", async () => {
|
|
214
|
-
// 1) LIST (status all) → the row carrying skillUid + live path.
|
|
215
|
-
fetchSpy.mockResolvedValueOnce(
|
|
216
|
-
jsonResponse({
|
|
217
|
-
suggestions: [
|
|
218
|
-
{
|
|
219
|
-
suggestionId: "sgn_9",
|
|
220
|
-
skillUid: "skl_yyy",
|
|
221
|
-
authorPersonUid: "prs_author",
|
|
222
|
-
status: "open",
|
|
223
|
-
baseChanged: false,
|
|
224
|
-
path: "skills/foo/SKILL.md",
|
|
225
|
-
createdAt: "2026-07-09",
|
|
226
|
-
},
|
|
227
|
-
],
|
|
228
|
-
count: 1,
|
|
229
|
-
}),
|
|
230
|
-
);
|
|
231
|
-
// 2) ACCEPT → merged + closed.
|
|
232
|
-
fetchSpy.mockResolvedValueOnce(
|
|
233
|
-
jsonResponse({
|
|
234
|
-
ok: true,
|
|
235
|
-
accepted: true,
|
|
236
|
-
liveSkill: true,
|
|
237
|
-
skillUid: "skl_yyy",
|
|
238
|
-
suggestionId: "sgn_9",
|
|
239
|
-
authorPersonUid: "prs_author",
|
|
240
|
-
acceptedBy: "prs_me",
|
|
241
|
-
baseChanged: false,
|
|
242
|
-
reindex: true,
|
|
243
|
-
message: "Suggestion accepted — the skill was updated to the proposed version.",
|
|
244
|
-
}),
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
await buildProgram().parseAsync(
|
|
248
|
-
["skill", "--company", "acme", "review", "sgn_9", "--accept"],
|
|
249
|
-
{ from: "user" },
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
// First call is the LIST lookup...
|
|
253
|
-
expect(String(fetchSpy.mock.calls[0][0])).toMatch(
|
|
254
|
-
/\/v1\/files\/skills\/company\/acme\/suggestions\/list$/,
|
|
255
|
-
);
|
|
256
|
-
// ...second is the wired ACCEPT route with the authoritative path.
|
|
257
|
-
const acceptCall = fetchSpy.mock.calls[1];
|
|
258
|
-
expect(String(acceptCall[0])).toMatch(
|
|
259
|
-
/\/v1\/files\/skills\/company\/acme\/skl_yyy\/suggestions\/sgn_9\/accept$/,
|
|
260
|
-
);
|
|
261
|
-
expect(JSON.parse((acceptCall[1]?.body as string) ?? "{}")).toEqual({
|
|
262
|
-
path: "skills/foo/SKILL.md",
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
expect(joinedLog()).toMatch(/merged and closed/);
|
|
266
|
-
expect(joinedLog()).toContain("prs_me");
|
|
267
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
// ===========================================================================
|
|
272
|
-
// AC3 — lock-safe suggest (no client-side gate)
|
|
273
|
-
// ===========================================================================
|
|
274
|
-
|
|
275
|
-
describe("AC3: suggest never runs a client-side lock/permission pre-check", () => {
|
|
276
|
-
it("issues exactly one network call — the CREATE POST — with no pre-flight lookup", async () => {
|
|
277
|
-
const dir = makeSkillDir("skl_locked000000000000000000", "body\n");
|
|
278
|
-
const gitBase: GitBaseReader = vi.fn(async () => null); // no base → full-file proposal
|
|
279
|
-
fetchSpy.mockResolvedValueOnce(
|
|
280
|
-
jsonResponse({
|
|
281
|
-
suggestionId: "sgn_x",
|
|
282
|
-
skillUid: "skl_locked000000000000000000",
|
|
283
|
-
status: "open",
|
|
284
|
-
authorPersonUid: "prs_me",
|
|
285
|
-
payloadFormat: "full-file",
|
|
286
|
-
baseContentHash: "h",
|
|
287
|
-
}),
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
await buildProgram({ gitBase }).parseAsync(
|
|
291
|
-
["skill", "--company", "acme", "suggest", dir],
|
|
292
|
-
{ from: "user" },
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
// A lock check would be a SEPARATE GET before the POST — there is none.
|
|
296
|
-
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
297
|
-
expect(String(fetchSpy.mock.calls[0][0])).toContain("/suggestions");
|
|
298
|
-
expect(fetchSpy.mock.calls[0][1]?.method).toBe("POST");
|
|
299
|
-
// A full-file proposal carries a baseContentHash the server requires.
|
|
300
|
-
const body = JSON.parse((fetchSpy.mock.calls[0][1]?.body as string) ?? "{}");
|
|
301
|
-
expect(body.proposedContent).toContain("body");
|
|
302
|
-
expect(typeof body.baseContentHash).toBe("string");
|
|
303
|
-
expect(body.baseContent).toBeUndefined();
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
// ===========================================================================
|
|
308
|
-
// suggest — base resolution + guardrails
|
|
309
|
-
// ===========================================================================
|
|
310
|
-
|
|
311
|
-
describe("hq skill suggest — base + guardrails", () => {
|
|
312
|
-
it("errors (no fetch) when the working tree matches its base", async () => {
|
|
313
|
-
const dir = makeSkillDir(UID, "same\n");
|
|
314
|
-
const same = fs.readFileSync(path.join(dir, "SKILL.md"), "utf-8");
|
|
315
|
-
const gitBase: GitBaseReader = vi.fn(async () => same);
|
|
316
|
-
|
|
317
|
-
await expect(
|
|
318
|
-
buildProgram({ gitBase }).parseAsync(
|
|
319
|
-
["skill", "--company", "acme", "suggest", dir, "--diff"],
|
|
320
|
-
{ from: "user" },
|
|
321
|
-
),
|
|
322
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
323
|
-
|
|
324
|
-
expect(joinedErr()).toMatch(/No changes to propose/);
|
|
325
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it("--diff errors when no base can be resolved", async () => {
|
|
329
|
-
const dir = makeSkillDir(UID, "body\n");
|
|
330
|
-
const gitBase: GitBaseReader = vi.fn(async () => null);
|
|
331
|
-
|
|
332
|
-
await expect(
|
|
333
|
-
buildProgram({ gitBase }).parseAsync(
|
|
334
|
-
["skill", "--company", "acme", "suggest", dir, "--diff"],
|
|
335
|
-
{ from: "user" },
|
|
336
|
-
),
|
|
337
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
338
|
-
|
|
339
|
-
expect(joinedErr()).toMatch(/--diff needs a base/);
|
|
340
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it("uses an explicit --base file as the diff base", async () => {
|
|
344
|
-
const dir = makeSkillDir(UID, "new content\n");
|
|
345
|
-
const baseFile = path.join(dir, "base.md");
|
|
346
|
-
fs.writeFileSync(baseFile, `---\nskill_uid: ${UID}\n---\nold content\n`);
|
|
347
|
-
const gitBase: GitBaseReader = vi.fn(async () => "SHOULD_NOT_BE_USED");
|
|
348
|
-
fetchSpy.mockResolvedValueOnce(
|
|
349
|
-
jsonResponse({
|
|
350
|
-
suggestionId: "sgn_b",
|
|
351
|
-
skillUid: UID,
|
|
352
|
-
status: "open",
|
|
353
|
-
authorPersonUid: "prs_me",
|
|
354
|
-
payloadFormat: "diff",
|
|
355
|
-
}),
|
|
356
|
-
);
|
|
357
|
-
|
|
358
|
-
await buildProgram({ gitBase }).parseAsync(
|
|
359
|
-
["skill", "--company", "acme", "suggest", dir, "--base", baseFile],
|
|
360
|
-
{ from: "user" },
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
expect(gitBase).not.toHaveBeenCalled(); // --base wins over git HEAD
|
|
364
|
-
const body = JSON.parse((fetchSpy.mock.calls[0][1]?.body as string) ?? "{}");
|
|
365
|
-
expect(body.baseContent).toContain("old content");
|
|
366
|
-
expect(body.proposedContent).toContain("new content");
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it("errors when the SKILL.md has no skill_uid", async () => {
|
|
370
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-skill-"));
|
|
371
|
-
tmpDirs.push(dir);
|
|
372
|
-
fs.writeFileSync(path.join(dir, "SKILL.md"), "# no frontmatter uid\n");
|
|
373
|
-
const gitBase: GitBaseReader = vi.fn(async () => null);
|
|
374
|
-
|
|
375
|
-
await expect(
|
|
376
|
-
buildProgram({ gitBase }).parseAsync(
|
|
377
|
-
["skill", "--company", "acme", "suggest", dir],
|
|
378
|
-
{ from: "user" },
|
|
379
|
-
),
|
|
380
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
381
|
-
|
|
382
|
-
expect(joinedErr()).toMatch(/no skill_uid/);
|
|
383
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
it("maps a 403 non-membership error from the CREATE route", async () => {
|
|
387
|
-
const dir = makeSkillDir(UID, "body\n");
|
|
388
|
-
const gitBase: GitBaseReader = vi.fn(async () => null);
|
|
389
|
-
fetchSpy.mockResolvedValueOnce(
|
|
390
|
-
jsonResponse({ error: "Caller is not a member", code: "WRITE_NOT_MEMBER" }, 403),
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
await expect(
|
|
394
|
-
buildProgram({ gitBase }).parseAsync(
|
|
395
|
-
["skill", "--company", "acme", "suggest", dir],
|
|
396
|
-
{ from: "user" },
|
|
397
|
-
),
|
|
398
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
399
|
-
|
|
400
|
-
expect(joinedErr()).toMatch(/not a member/);
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// ===========================================================================
|
|
405
|
-
// list-suggestions
|
|
406
|
-
// ===========================================================================
|
|
407
|
-
|
|
408
|
-
describe("hq skill list-suggestions", () => {
|
|
409
|
-
it("POSTs {status} (+ skillUid when scoped) to the LIST route", async () => {
|
|
410
|
-
fetchSpy.mockResolvedValueOnce(jsonResponse({ suggestions: [], count: 0 }));
|
|
411
|
-
|
|
412
|
-
await buildProgram().parseAsync(
|
|
413
|
-
["skill", "--company", "acme", "list-suggestions", "--skill", "skl_yyy", "--status", "all"],
|
|
414
|
-
{ from: "user" },
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
const call = fetchSpy.mock.calls[0];
|
|
418
|
-
expect(String(call[0])).toMatch(
|
|
419
|
-
/\/v1\/files\/skills\/company\/acme\/suggestions\/list$/,
|
|
420
|
-
);
|
|
421
|
-
expect(JSON.parse((call[1]?.body as string) ?? "{}")).toEqual({
|
|
422
|
-
status: "all",
|
|
423
|
-
skillUid: "skl_yyy",
|
|
424
|
-
});
|
|
425
|
-
expect(joinedLog()).toMatch(/review inbox is empty/);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it("defaults status to open and emits raw JSON with --json", async () => {
|
|
429
|
-
fetchSpy.mockResolvedValueOnce(
|
|
430
|
-
jsonResponse({ suggestions: [], count: 0 }),
|
|
431
|
-
);
|
|
432
|
-
await buildProgram().parseAsync(
|
|
433
|
-
["skill", "--company", "acme", "list-suggestions", "--json"],
|
|
434
|
-
{ from: "user" },
|
|
435
|
-
);
|
|
436
|
-
expect(JSON.parse((fetchSpy.mock.calls[0][1]?.body as string) ?? "{}")).toEqual({
|
|
437
|
-
status: "open",
|
|
438
|
-
});
|
|
439
|
-
expect(joinedLog()).toContain('"count": 0');
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it("rejects an invalid --status without a network call", async () => {
|
|
443
|
-
await expect(
|
|
444
|
-
buildProgram().parseAsync(
|
|
445
|
-
["skill", "--company", "acme", "list-suggestions", "--status", "bogus"],
|
|
446
|
-
{ from: "user" },
|
|
447
|
-
),
|
|
448
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
449
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
// ===========================================================================
|
|
454
|
-
// review — decline, conflicts, validation
|
|
455
|
-
// ===========================================================================
|
|
456
|
-
|
|
457
|
-
describe("hq skill review", () => {
|
|
458
|
-
const openRow = {
|
|
459
|
-
suggestions: [
|
|
460
|
-
{
|
|
461
|
-
suggestionId: "sgn_9",
|
|
462
|
-
skillUid: "skl_yyy",
|
|
463
|
-
authorPersonUid: "prs_author",
|
|
464
|
-
status: "open",
|
|
465
|
-
baseChanged: false,
|
|
466
|
-
path: "skills/foo/SKILL.md",
|
|
467
|
-
createdAt: "2026-07-09",
|
|
468
|
-
},
|
|
469
|
-
],
|
|
470
|
-
count: 1,
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
it("--decline posts the reason and leaves the skill unchanged", async () => {
|
|
474
|
-
fetchSpy.mockResolvedValueOnce(jsonResponse(openRow));
|
|
475
|
-
fetchSpy.mockResolvedValueOnce(
|
|
476
|
-
jsonResponse({
|
|
477
|
-
ok: true,
|
|
478
|
-
declined: true,
|
|
479
|
-
skillUid: "skl_yyy",
|
|
480
|
-
suggestionId: "sgn_9",
|
|
481
|
-
declinedBy: "prs_me",
|
|
482
|
-
status: "declined",
|
|
483
|
-
reason: "not now",
|
|
484
|
-
}),
|
|
485
|
-
);
|
|
486
|
-
|
|
487
|
-
await buildProgram().parseAsync(
|
|
488
|
-
["skill", "--company", "acme", "review", "sgn_9", "--decline", "--reason", "not now"],
|
|
489
|
-
{ from: "user" },
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
const declineCall = fetchSpy.mock.calls[1];
|
|
493
|
-
expect(String(declineCall[0])).toMatch(
|
|
494
|
-
/\/skl_yyy\/suggestions\/sgn_9\/decline$/,
|
|
495
|
-
);
|
|
496
|
-
expect(JSON.parse((declineCall[1]?.body as string) ?? "{}")).toEqual({
|
|
497
|
-
reason: "not now",
|
|
498
|
-
});
|
|
499
|
-
expect(joinedLog()).toMatch(/declined/);
|
|
500
|
-
expect(joinedLog()).toContain("not now");
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
it("--accept surfaces a base-changed conflict with acknowledge guidance", async () => {
|
|
504
|
-
fetchSpy.mockResolvedValueOnce(
|
|
505
|
-
jsonResponse({
|
|
506
|
-
suggestions: [{ ...openRow.suggestions[0], baseChanged: true }],
|
|
507
|
-
count: 1,
|
|
508
|
-
}),
|
|
509
|
-
);
|
|
510
|
-
fetchSpy.mockResolvedValueOnce(
|
|
511
|
-
jsonResponse(
|
|
512
|
-
{
|
|
513
|
-
error: "The skill changed since this suggestion was written.",
|
|
514
|
-
code: "WRITE_SKILL_SUGGESTION_BASE_CHANGED",
|
|
515
|
-
baseChanged: true,
|
|
516
|
-
},
|
|
517
|
-
409,
|
|
518
|
-
),
|
|
519
|
-
);
|
|
520
|
-
|
|
521
|
-
await expect(
|
|
522
|
-
buildProgram().parseAsync(
|
|
523
|
-
["skill", "--company", "acme", "review", "sgn_9", "--accept"],
|
|
524
|
-
{ from: "user" },
|
|
525
|
-
),
|
|
526
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
527
|
-
|
|
528
|
-
expect(joinedErr()).toMatch(/--acknowledge-base-changed/);
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
it("--accept --acknowledge-base-changed forwards the flag in the body", async () => {
|
|
532
|
-
fetchSpy.mockResolvedValueOnce(jsonResponse(openRow));
|
|
533
|
-
fetchSpy.mockResolvedValueOnce(
|
|
534
|
-
jsonResponse({
|
|
535
|
-
ok: true,
|
|
536
|
-
accepted: true,
|
|
537
|
-
skillUid: "skl_yyy",
|
|
538
|
-
suggestionId: "sgn_9",
|
|
539
|
-
acceptedBy: "prs_me",
|
|
540
|
-
baseChanged: true,
|
|
541
|
-
reindex: true,
|
|
542
|
-
}),
|
|
543
|
-
);
|
|
544
|
-
|
|
545
|
-
await buildProgram().parseAsync(
|
|
546
|
-
["skill", "--company", "acme", "review", "sgn_9", "--accept", "--acknowledge-base-changed"],
|
|
547
|
-
{ from: "user" },
|
|
548
|
-
);
|
|
549
|
-
|
|
550
|
-
expect(JSON.parse((fetchSpy.mock.calls[1][1]?.body as string) ?? "{}")).toEqual({
|
|
551
|
-
path: "skills/foo/SKILL.md",
|
|
552
|
-
acknowledgeBaseChanged: true,
|
|
553
|
-
});
|
|
554
|
-
expect(joinedLog()).toMatch(/merged and closed/);
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
it("requires exactly one of --accept / --decline", async () => {
|
|
558
|
-
await expect(
|
|
559
|
-
buildProgram().parseAsync(
|
|
560
|
-
["skill", "--company", "acme", "review", "sgn_9"],
|
|
561
|
-
{ from: "user" },
|
|
562
|
-
),
|
|
563
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
564
|
-
expect(joinedErr()).toMatch(/exactly one of --accept or --decline/);
|
|
565
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
it("errors when the suggestion is not in the inbox", async () => {
|
|
569
|
-
fetchSpy.mockResolvedValueOnce(jsonResponse({ suggestions: [], count: 0 }));
|
|
570
|
-
await expect(
|
|
571
|
-
buildProgram().parseAsync(
|
|
572
|
-
["skill", "--company", "acme", "review", "sgn_missing", "--accept"],
|
|
573
|
-
{ from: "user" },
|
|
574
|
-
),
|
|
575
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
576
|
-
expect(joinedErr()).toMatch(/not in your review inbox/);
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
it("rejects a malformed suggestion id before any network call", async () => {
|
|
580
|
-
await expect(
|
|
581
|
-
buildProgram().parseAsync(
|
|
582
|
-
["skill", "--company", "acme", "review", "not-an-id", "--accept"],
|
|
583
|
-
{ from: "user" },
|
|
584
|
-
),
|
|
585
|
-
).rejects.toThrow(/__EXIT__:1/);
|
|
586
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
// ===========================================================================
|
|
591
|
-
// Pure helpers
|
|
592
|
-
// ===========================================================================
|
|
593
|
-
|
|
594
|
-
describe("parseSkillUid", () => {
|
|
595
|
-
it("reads a top-level skl_ uid from frontmatter", () => {
|
|
596
|
-
expect(parseSkillUid(`---\nskill_uid: ${UID}\nname: x\n---\nbody`)).toBe(UID);
|
|
597
|
-
});
|
|
598
|
-
it("returns undefined with no frontmatter", () => {
|
|
599
|
-
expect(parseSkillUid("# just a heading\n")).toBeUndefined();
|
|
600
|
-
});
|
|
601
|
-
it("returns undefined for a non-skl_ value", () => {
|
|
602
|
-
expect(parseSkillUid("---\nskill_uid: nope\n---\n")).toBeUndefined();
|
|
603
|
-
});
|
|
604
|
-
it("returns undefined for a non-string uid", () => {
|
|
605
|
-
expect(parseSkillUid("---\nskill_uid: 123\n---\n")).toBeUndefined();
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
describe("buildSuggestionCreateBody", () => {
|
|
610
|
-
it("sends baseContent (diff path) and drops a derived hash", () => {
|
|
611
|
-
const body = buildSuggestionCreateBody({
|
|
612
|
-
proposedContent: "new",
|
|
613
|
-
baseContent: "old",
|
|
614
|
-
note: " ctx ",
|
|
615
|
-
});
|
|
616
|
-
expect(body).toEqual({ proposedContent: "new", baseContent: "old", authorNote: "ctx" });
|
|
617
|
-
});
|
|
618
|
-
it("sends baseContentHash (full-file path) when there is no base", () => {
|
|
619
|
-
const body = buildSuggestionCreateBody({ proposedContent: "solo" });
|
|
620
|
-
expect(body).toEqual({
|
|
621
|
-
proposedContent: "solo",
|
|
622
|
-
baseContentHash: sha256Hex("solo"),
|
|
623
|
-
});
|
|
624
|
-
});
|
|
625
|
-
it("drops an empty note", () => {
|
|
626
|
-
const body = buildSuggestionCreateBody({ proposedContent: "x", note: " " });
|
|
627
|
-
expect(body.authorNote).toBeUndefined();
|
|
628
|
-
});
|
|
629
|
-
it("throws on a no-op (base === proposed)", () => {
|
|
630
|
-
expect(() =>
|
|
631
|
-
buildSuggestionCreateBody({ proposedContent: "same", baseContent: "same" }),
|
|
632
|
-
).toThrow(/No changes to propose/);
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
describe("mapSkillError", () => {
|
|
637
|
-
it("maps auth + prefers the server message", () => {
|
|
638
|
-
expect(mapSkillError(401, {})).toMatch(/hq login/);
|
|
639
|
-
expect(mapSkillError(403, { error: "You need write access" })).toBe(
|
|
640
|
-
"You need write access",
|
|
641
|
-
);
|
|
642
|
-
expect(mapSkillError(404, { error: "Skill not found" })).toBe("Skill not found");
|
|
643
|
-
expect(mapSkillError(409, { message: "already accepted" })).toBe("already accepted");
|
|
644
|
-
expect(mapSkillError(500, {})).toMatch(/Server error/);
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
describe("resolveCompanySlug", () => {
|
|
649
|
-
it("prefers the explicit flag", () => {
|
|
650
|
-
expect(resolveCompanySlug("acme", "/nonexistent")).toBe("acme");
|
|
651
|
-
});
|
|
652
|
-
it("falls back to .hq/config.json activeCompany", () => {
|
|
653
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "hq-root-"));
|
|
654
|
-
tmpDirs.push(root);
|
|
655
|
-
fs.mkdirSync(path.join(root, ".hq"));
|
|
656
|
-
fs.writeFileSync(
|
|
657
|
-
path.join(root, ".hq", "config.json"),
|
|
658
|
-
JSON.stringify({ activeCompany: "beta" }),
|
|
659
|
-
);
|
|
660
|
-
expect(resolveCompanySlug(undefined, root)).toBe("beta");
|
|
661
|
-
});
|
|
662
|
-
it("throws when neither is available", () => {
|
|
663
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "hq-root-"));
|
|
664
|
-
tmpDirs.push(root);
|
|
665
|
-
expect(() => resolveCompanySlug(undefined, root)).toThrow(/No company specified/);
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
describe("resolveSkillTarget", () => {
|
|
670
|
-
it("resolves a directory to its SKILL.md and reads the uid", () => {
|
|
671
|
-
const dir = makeSkillDir(UID, "hello\n");
|
|
672
|
-
const r = resolveSkillTarget(dir, { cwd: dir, hqRoot: "/x", companySlug: "acme" });
|
|
673
|
-
expect(r.skillUid).toBe(UID);
|
|
674
|
-
expect(r.content).toContain("hello");
|
|
675
|
-
expect(r.filePath.endsWith("SKILL.md")).toBe(true);
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
it("resolves a direct SKILL.md file path", () => {
|
|
679
|
-
const dir = makeSkillDir(UID, "hi\n");
|
|
680
|
-
const file = path.join(dir, "SKILL.md");
|
|
681
|
-
const r = resolveSkillTarget(file, { cwd: "/x", hqRoot: "/x", companySlug: "acme" });
|
|
682
|
-
expect(r.skillUid).toBe(UID);
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
it("resolves a skl_ uid by scanning the company skills dir", () => {
|
|
686
|
-
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-root-"));
|
|
687
|
-
tmpDirs.push(hqRoot);
|
|
688
|
-
const skillDir = path.join(hqRoot, "companies", "acme", "skills", "foo");
|
|
689
|
-
fs.mkdirSync(skillDir, { recursive: true });
|
|
690
|
-
fs.writeFileSync(
|
|
691
|
-
path.join(skillDir, "SKILL.md"),
|
|
692
|
-
`---\nskill_uid: ${UID}\n---\ncontent\n`,
|
|
693
|
-
);
|
|
694
|
-
const emptyCwd = fs.mkdtempSync(path.join(os.tmpdir(), "hq-cwd-"));
|
|
695
|
-
tmpDirs.push(emptyCwd);
|
|
696
|
-
|
|
697
|
-
const r = resolveSkillTarget(UID, { cwd: emptyCwd, hqRoot, companySlug: "acme" });
|
|
698
|
-
expect(r.skillUid).toBe(UID);
|
|
699
|
-
expect(r.filePath).toBe(path.join(skillDir, "SKILL.md"));
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
it("throws for a missing path", () => {
|
|
703
|
-
expect(() =>
|
|
704
|
-
resolveSkillTarget("/no/such/dir", { cwd: "/x", hqRoot: "/x", companySlug: "acme" }),
|
|
705
|
-
).toThrow(/No SKILL.md found/);
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
it("throws when the resolved SKILL.md has no uid", () => {
|
|
709
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-skill-"));
|
|
710
|
-
tmpDirs.push(dir);
|
|
711
|
-
fs.writeFileSync(path.join(dir, "SKILL.md"), "# no uid\n");
|
|
712
|
-
expect(() =>
|
|
713
|
-
resolveSkillTarget(dir, { cwd: dir, hqRoot: "/x", companySlug: "acme" }),
|
|
714
|
-
).toThrow(/no skill_uid/);
|
|
715
|
-
});
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
describe("findSkillFileByUid", () => {
|
|
719
|
-
it("returns null when no skill matches", () => {
|
|
720
|
-
const dir = makeSkillDir(UID, "x\n");
|
|
721
|
-
expect(findSkillFileByUid([dir], "skl_other")).toBeNull();
|
|
722
|
-
});
|
|
723
|
-
it("skips ignored dirs and finds a nested match", () => {
|
|
724
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "hq-root-"));
|
|
725
|
-
tmpDirs.push(root);
|
|
726
|
-
const nested = path.join(root, "a", "b", "skill");
|
|
727
|
-
fs.mkdirSync(nested, { recursive: true });
|
|
728
|
-
fs.writeFileSync(path.join(nested, "SKILL.md"), `---\nskill_uid: ${UID}\n---\n`);
|
|
729
|
-
expect(findSkillFileByUid([root], UID)).toBe(path.join(nested, "SKILL.md"));
|
|
730
|
-
});
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
describe("formatSuggestionsList", () => {
|
|
734
|
-
const row: SuggestionRow = {
|
|
735
|
-
suggestionId: "sgn_1",
|
|
736
|
-
skillUid: "skl_a",
|
|
737
|
-
authorPersonUid: "prs_x",
|
|
738
|
-
status: "open",
|
|
739
|
-
baseChanged: false,
|
|
740
|
-
presentation: "diff",
|
|
741
|
-
unifiedDiff: "--- a\n+++ b\n@@ -1 +1 @@\n-a\n+b\n",
|
|
742
|
-
authorNote: "why",
|
|
743
|
-
createdAt: "2026-07-09T00:00:00Z",
|
|
744
|
-
path: "skills/a/SKILL.md",
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
it("renders an empty-inbox line", () => {
|
|
748
|
-
expect(formatSuggestionsList([])).toMatch(/review inbox is empty/);
|
|
749
|
-
});
|
|
750
|
-
it("renders a header + row + note", () => {
|
|
751
|
-
const out = formatSuggestionsList([row]);
|
|
752
|
-
expect(out).toContain("SUGGESTION_ID");
|
|
753
|
-
expect(out).toContain("sgn_1");
|
|
754
|
-
expect(out).toContain("note: why");
|
|
755
|
-
expect(out).not.toContain("+b"); // no diff without --show-diff
|
|
756
|
-
});
|
|
757
|
-
it("includes the diff with showDiff", () => {
|
|
758
|
-
const out = formatSuggestionsList([row], { showDiff: true });
|
|
759
|
-
expect(out).toContain("-a");
|
|
760
|
-
expect(out).toContain("+b");
|
|
761
|
-
});
|
|
762
|
-
it("shows full file when the base changed", () => {
|
|
763
|
-
const out = formatSuggestionsList(
|
|
764
|
-
[{ ...row, presentation: "full-file", unifiedDiff: undefined, fullContent: "WHOLE", baseChanged: true }],
|
|
765
|
-
{ showDiff: true },
|
|
766
|
-
);
|
|
767
|
-
expect(out).toContain("full file");
|
|
768
|
-
expect(out).toContain("WHOLE");
|
|
769
|
-
});
|
|
770
|
-
});
|