@indigoai-us/hq-cli 5.77.14 → 5.79.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 +31 -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/meetings.js +16 -9
- package/dist/commands/members.js +16 -5
- package/dist/commands/pack-install.d.ts +14 -0
- package/dist/commands/pack-install.js +42 -2
- package/dist/commands/pkg-install.js +39 -2
- package/dist/commands/run.js +6 -2
- package/dist/commands/secrets.js +120 -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 -2256
- package/src/commands/pack-update-cache.test.ts +0 -149
- package/src/commands/packs-update-api-key.test.ts +0 -105
- 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 -103
- package/src/commands/pkg-install.ts +0 -221
- 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 -190
- 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 -2050
- package/src/commands/secrets.ts +0 -2249
- 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,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Marketplace artifact verification (US-021, INSTALL side) tests.
|
|
3
|
-
*
|
|
4
|
-
* Proves the install-time guarantee: the bytes we install are EXACTLY the bytes
|
|
5
|
-
* a moderator approved. Covers the two E2E behaviors required by the story:
|
|
6
|
-
* - an approved artifact whose S3 object is mutated → hash mismatch → REFUSE.
|
|
7
|
-
* - signature verification against the platform Ed25519 PUBLIC key.
|
|
8
|
-
*
|
|
9
|
-
* SHARED CONTRACT mirror — we reproduce the publish-side signing here with an
|
|
10
|
-
* ephemeral in-test keypair (no key material in the repo) to prove both sides
|
|
11
|
-
* agree byte-for-byte.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { describe, it, expect } from 'vitest';
|
|
15
|
-
import {
|
|
16
|
-
generateKeyPairSync,
|
|
17
|
-
createHash,
|
|
18
|
-
sign as cryptoSign,
|
|
19
|
-
} from 'node:crypto';
|
|
20
|
-
import {
|
|
21
|
-
verifyArtifact,
|
|
22
|
-
computeArtifactHash,
|
|
23
|
-
ArtifactVerificationError,
|
|
24
|
-
ARTIFACT_HASH_ALG,
|
|
25
|
-
} from './pack-install.js';
|
|
26
|
-
|
|
27
|
-
// Ephemeral platform keypair (regenerated each run — never committed).
|
|
28
|
-
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
|
|
29
|
-
const publicKeyPem = publicKey.export({ type: 'spki', format: 'pem' }).toString();
|
|
30
|
-
|
|
31
|
-
/** Reproduce the hq-pro publish-side: sha256 hex hash + Ed25519 over the hash. */
|
|
32
|
-
function publishSide(bytes: Buffer): { contentHash: string; signature: string } {
|
|
33
|
-
const contentHash = createHash('sha256').update(bytes).digest('hex');
|
|
34
|
-
const signature = cryptoSign(
|
|
35
|
-
null,
|
|
36
|
-
Buffer.from(contentHash, 'utf-8'),
|
|
37
|
-
privateKey,
|
|
38
|
-
).toString('base64');
|
|
39
|
-
return { contentHash, signature };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const APPROVED_BYTES = Buffer.from('the-approved-pack.tar.gz-bytes');
|
|
43
|
-
|
|
44
|
-
describe('computeArtifactHash', () => {
|
|
45
|
-
it('matches a lowercase-hex sha256 (shared contract with publish)', () => {
|
|
46
|
-
const expected = createHash('sha256').update(APPROVED_BYTES).digest('hex');
|
|
47
|
-
expect(computeArtifactHash(APPROVED_BYTES)).toBe(expected);
|
|
48
|
-
expect(ARTIFACT_HASH_ALG).toBe('sha256');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('verifyArtifact — integrity (hash)', () => {
|
|
53
|
-
it('passes when the downloaded bytes match the pinned hash + valid signature', () => {
|
|
54
|
-
const { contentHash, signature } = publishSide(APPROVED_BYTES);
|
|
55
|
-
expect(() =>
|
|
56
|
-
verifyArtifact({
|
|
57
|
-
tarballBytes: APPROVED_BYTES,
|
|
58
|
-
expectedHash: contentHash,
|
|
59
|
-
signature,
|
|
60
|
-
publicKey: publicKeyPem,
|
|
61
|
-
requireSignature: true,
|
|
62
|
-
}),
|
|
63
|
-
).not.toThrow();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('E2E: a MUTATED S3 object → hash mismatch → REFUSES', () => {
|
|
67
|
-
// Publish/approval pinned the hash of APPROVED_BYTES…
|
|
68
|
-
const { contentHash, signature } = publishSide(APPROVED_BYTES);
|
|
69
|
-
// …but the bytes we actually downloaded were swapped by an attacker.
|
|
70
|
-
const mutatedBytes = Buffer.from('EVIL-swapped-pack.tar.gz-bytes');
|
|
71
|
-
|
|
72
|
-
expect(() =>
|
|
73
|
-
verifyArtifact({
|
|
74
|
-
tarballBytes: mutatedBytes,
|
|
75
|
-
expectedHash: contentHash,
|
|
76
|
-
signature,
|
|
77
|
-
publicKey: publicKeyPem,
|
|
78
|
-
}),
|
|
79
|
-
).toThrow(ArtifactVerificationError);
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
verifyArtifact({
|
|
83
|
-
tarballBytes: mutatedBytes,
|
|
84
|
-
expectedHash: contentHash,
|
|
85
|
-
});
|
|
86
|
-
} catch (e) {
|
|
87
|
-
expect((e as Error).message).toMatch(/hash mismatch/i);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('refuses when the listing provides no valid hash', () => {
|
|
92
|
-
expect(() =>
|
|
93
|
-
verifyArtifact({ tarballBytes: APPROVED_BYTES, expectedHash: '' }),
|
|
94
|
-
).toThrow(/valid sha256 content hash/i);
|
|
95
|
-
expect(() =>
|
|
96
|
-
verifyArtifact({ tarballBytes: APPROVED_BYTES, expectedHash: 'not-a-hash' }),
|
|
97
|
-
).toThrow(ArtifactVerificationError);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('verifyArtifact — authenticity (signature)', () => {
|
|
102
|
-
it('refuses a hash-valid artifact whose signature was forged by a different key', () => {
|
|
103
|
-
const { contentHash } = publishSide(APPROVED_BYTES);
|
|
104
|
-
// Attacker signs the (correct) hash with their OWN key.
|
|
105
|
-
const { privateKey: evilKey } = generateKeyPairSync('ed25519');
|
|
106
|
-
const forged = cryptoSign(
|
|
107
|
-
null,
|
|
108
|
-
Buffer.from(contentHash, 'utf-8'),
|
|
109
|
-
evilKey,
|
|
110
|
-
).toString('base64');
|
|
111
|
-
|
|
112
|
-
expect(() =>
|
|
113
|
-
verifyArtifact({
|
|
114
|
-
tarballBytes: APPROVED_BYTES,
|
|
115
|
-
expectedHash: contentHash,
|
|
116
|
-
signature: forged,
|
|
117
|
-
publicKey: publicKeyPem, // platform key — won't validate the forgery
|
|
118
|
-
}),
|
|
119
|
-
).toThrow(/signature is invalid/i);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('refuses on a corrupt/garbage signature', () => {
|
|
123
|
-
const { contentHash } = publishSide(APPROVED_BYTES);
|
|
124
|
-
expect(() =>
|
|
125
|
-
verifyArtifact({
|
|
126
|
-
tarballBytes: APPROVED_BYTES,
|
|
127
|
-
expectedHash: contentHash,
|
|
128
|
-
signature: 'not-base64-or-a-real-sig!!!',
|
|
129
|
-
publicKey: publicKeyPem,
|
|
130
|
-
}),
|
|
131
|
-
).toThrow(ArtifactVerificationError);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('refuses on an invalid public key', () => {
|
|
135
|
-
const { contentHash, signature } = publishSide(APPROVED_BYTES);
|
|
136
|
-
expect(() =>
|
|
137
|
-
verifyArtifact({
|
|
138
|
-
tarballBytes: APPROVED_BYTES,
|
|
139
|
-
expectedHash: contentHash,
|
|
140
|
-
signature,
|
|
141
|
-
publicKey: 'not a real pem',
|
|
142
|
-
}),
|
|
143
|
-
).toThrow(/public key/i);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('verifyArtifact — deferred-key window', () => {
|
|
148
|
-
it('hash-verifies but skips signature when none provided (requireSignature=false)', () => {
|
|
149
|
-
const { contentHash } = publishSide(APPROVED_BYTES);
|
|
150
|
-
expect(() =>
|
|
151
|
-
verifyArtifact({ tarballBytes: APPROVED_BYTES, expectedHash: contentHash }),
|
|
152
|
-
).not.toThrow();
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('refuses an unsigned artifact when requireSignature=true', () => {
|
|
156
|
-
const { contentHash } = publishSide(APPROVED_BYTES);
|
|
157
|
-
expect(() =>
|
|
158
|
-
verifyArtifact({
|
|
159
|
-
tarballBytes: APPROVED_BYTES,
|
|
160
|
-
expectedHash: contentHash,
|
|
161
|
-
requireSignature: true,
|
|
162
|
-
}),
|
|
163
|
-
).toThrow(/unsigned/i);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('refuses when a signature is present but no public key is available (requireSignature=true)', () => {
|
|
167
|
-
const { contentHash, signature } = publishSide(APPROVED_BYTES);
|
|
168
|
-
expect(() =>
|
|
169
|
-
verifyArtifact({
|
|
170
|
-
tarballBytes: APPROVED_BYTES,
|
|
171
|
-
expectedHash: contentHash,
|
|
172
|
-
signature,
|
|
173
|
-
requireSignature: true,
|
|
174
|
-
}),
|
|
175
|
-
).toThrow(/public key/i);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
|
|
4
|
-
const mocks = vi.hoisted(() => ({
|
|
5
|
-
browserLogin: vi.fn(),
|
|
6
|
-
isExpiring: vi.fn(),
|
|
7
|
-
isMachineIdentity: vi.fn(),
|
|
8
|
-
loadCachedTokens: vi.fn(),
|
|
9
|
-
loadMachineCreds: vi.fn(),
|
|
10
|
-
CognitoAuthError: class TestCognitoAuthError extends Error {},
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
vi.mock("@indigoai-us/hq-cloud", () => ({
|
|
14
|
-
browserLogin: mocks.browserLogin,
|
|
15
|
-
clearCachedTokens: vi.fn(),
|
|
16
|
-
isExpiring: mocks.isExpiring,
|
|
17
|
-
isMachineIdentity: mocks.isMachineIdentity,
|
|
18
|
-
loadCachedTokens: mocks.loadCachedTokens,
|
|
19
|
-
loadMachineCreds: mocks.loadMachineCreds,
|
|
20
|
-
CognitoAuthError: mocks.CognitoAuthError,
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
vi.mock("../utils/cognito-session.js", () => ({
|
|
24
|
-
DEFAULT_COGNITO: {
|
|
25
|
-
region: "us-east-1",
|
|
26
|
-
userPoolDomain: "vault-indigo-hq-prod",
|
|
27
|
-
clientId: "client-123",
|
|
28
|
-
port: 8765,
|
|
29
|
-
identityProvider: "Google",
|
|
30
|
-
},
|
|
31
|
-
refreshCachedSession: vi.fn(),
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
import { registerAuthCommands } from "./auth.js";
|
|
35
|
-
|
|
36
|
-
class ProcessExitError extends Error {
|
|
37
|
-
constructor(readonly code: number) {
|
|
38
|
-
super(`process.exit(${code})`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe("hq auth login", () => {
|
|
43
|
-
it("REGRESSION: explains how to recover when the callback port is held by another login", async () => {
|
|
44
|
-
mocks.isMachineIdentity.mockReturnValue(false);
|
|
45
|
-
mocks.loadCachedTokens.mockReturnValue(undefined);
|
|
46
|
-
mocks.browserLogin.mockRejectedValue(
|
|
47
|
-
Object.assign(new Error("listen EADDRINUSE: address already in use 127.0.0.1:8765"), {
|
|
48
|
-
code: "EADDRINUSE",
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const errors: string[] = [];
|
|
53
|
-
const errorSpy = vi
|
|
54
|
-
.spyOn(console, "error")
|
|
55
|
-
.mockImplementation((...args: unknown[]) => errors.push(args.map(String).join(" ")));
|
|
56
|
-
const exitSpy = vi
|
|
57
|
-
.spyOn(process, "exit")
|
|
58
|
-
.mockImplementation(((code?: number) => {
|
|
59
|
-
throw new ProcessExitError(code ?? 0);
|
|
60
|
-
}) as never);
|
|
61
|
-
const program = new Command();
|
|
62
|
-
program.exitOverride();
|
|
63
|
-
registerAuthCommands(program);
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
await expect(program.parseAsync(["auth", "login"], { from: "user" })).rejects.toMatchObject({
|
|
67
|
-
code: 1,
|
|
68
|
-
});
|
|
69
|
-
} finally {
|
|
70
|
-
errorSpy.mockRestore();
|
|
71
|
-
exitSpy.mockRestore();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const output = errors.join("\n");
|
|
75
|
-
expect(output).toContain("Login failed: Browser-login callback port is already in use.");
|
|
76
|
-
expect(output).not.toContain("EADDRINUSE");
|
|
77
|
-
expect(output).toContain("callback port (127.0.0.1:8765) is already in use");
|
|
78
|
-
expect(output).toContain("Another `hq auth login` may still be waiting");
|
|
79
|
-
expect(output).toContain("stop its terminal/process, then retry");
|
|
80
|
-
expect(output).not.toContain("sign up at");
|
|
81
|
-
});
|
|
82
|
-
});
|
package/src/commands/auth.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `hq auth` — Cognito identity management for HQ.
|
|
3
|
-
*
|
|
4
|
-
* Subcommands:
|
|
5
|
-
* hq auth login — open the Cognito Hosted UI in the browser and cache tokens
|
|
6
|
-
* hq auth logout — clear the cached HQ session
|
|
7
|
-
* hq auth refresh — ensure a valid cached Cognito session (non-interactive)
|
|
8
|
-
* hq auth status — show whether a valid session is cached + expiry
|
|
9
|
-
*
|
|
10
|
-
* Sign-up is owned by the onboarding web app at
|
|
11
|
-
* https://onboarding.indigo-hq.com. `hq auth login` signs an existing account
|
|
12
|
-
* into this machine by writing ~/.hq/cognito-tokens.json; once cached, the
|
|
13
|
-
* session is kept valid by `hq auth refresh` / `hq-auth-refresh` and consumed
|
|
14
|
-
* by the deploy + sync skills.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { Command } from "commander";
|
|
18
|
-
import chalk from "chalk";
|
|
19
|
-
import {
|
|
20
|
-
browserLogin,
|
|
21
|
-
clearCachedTokens,
|
|
22
|
-
loadCachedTokens,
|
|
23
|
-
isExpiring,
|
|
24
|
-
isMachineIdentity,
|
|
25
|
-
loadMachineCreds,
|
|
26
|
-
CognitoAuthError,
|
|
27
|
-
} from "@indigoai-us/hq-cloud";
|
|
28
|
-
import {
|
|
29
|
-
DEFAULT_COGNITO,
|
|
30
|
-
refreshCachedSession,
|
|
31
|
-
} from "../utils/cognito-session.js";
|
|
32
|
-
import { cognitoConfigForLoginProvider } from "../utils/login-provider.js";
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Decode the (unverified) ID token payload for display purposes only.
|
|
36
|
-
* The token was just returned by Cognito's token endpoint, so its contents
|
|
37
|
-
* are trusted enough to print — we never use these claims for authorization.
|
|
38
|
-
*/
|
|
39
|
-
function peekIdToken(
|
|
40
|
-
idToken: string,
|
|
41
|
-
): { email?: string; sub?: string; entityType?: string; entityUid?: string } {
|
|
42
|
-
try {
|
|
43
|
-
const payload = idToken.split(".")[1];
|
|
44
|
-
if (!payload) return {};
|
|
45
|
-
const pad =
|
|
46
|
-
payload.length % 4 === 0 ? "" : "=".repeat(4 - (payload.length % 4));
|
|
47
|
-
const normalized =
|
|
48
|
-
payload.replace(/-/g, "+").replace(/_/g, "/") + pad;
|
|
49
|
-
const decoded = JSON.parse(
|
|
50
|
-
Buffer.from(normalized, "base64").toString("utf-8"),
|
|
51
|
-
);
|
|
52
|
-
return {
|
|
53
|
-
email: decoded.email,
|
|
54
|
-
sub: decoded.sub,
|
|
55
|
-
entityType: decoded["custom:entityType"],
|
|
56
|
-
entityUid: decoded["custom:entityUid"],
|
|
57
|
-
};
|
|
58
|
-
} catch {
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Display label for the local machine identity (company agents). */
|
|
64
|
-
function machineIdentityLabel(): string {
|
|
65
|
-
const creds = loadMachineCreds();
|
|
66
|
-
return creds ? `machine identity ${creds.username}` : "machine identity";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function isCallbackPortCollision(error: unknown): boolean {
|
|
70
|
-
if (!error || typeof error !== "object") return false;
|
|
71
|
-
const { code, message } = error as NodeJS.ErrnoException;
|
|
72
|
-
return code === "EADDRINUSE" || message?.includes("EADDRINUSE") === true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function callbackPortCollisionGuidance(port: number): string {
|
|
76
|
-
return (
|
|
77
|
-
` The browser-login callback port (127.0.0.1:${port}) is already in use. ` +
|
|
78
|
-
"Another `hq auth login` may still be waiting for browser sign-in. Finish that login, " +
|
|
79
|
-
"or stop its terminal/process, then retry."
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function registerAuthCommands(program: Command): void {
|
|
84
|
-
const authCmd = program
|
|
85
|
-
.command("auth")
|
|
86
|
-
.description("Manage the local HQ Cognito session");
|
|
87
|
-
|
|
88
|
-
authCmd
|
|
89
|
-
.command("login")
|
|
90
|
-
.description(
|
|
91
|
-
"Sign in to HQ — opens the Cognito Hosted UI and caches tokens locally",
|
|
92
|
-
)
|
|
93
|
-
.option(
|
|
94
|
-
"--provider <provider>",
|
|
95
|
-
"OAuth provider to use: google, microsoft, or picker",
|
|
96
|
-
)
|
|
97
|
-
.action(async (options: { provider?: string }) => {
|
|
98
|
-
if (isMachineIdentity()) {
|
|
99
|
-
console.log(
|
|
100
|
-
chalk.green(
|
|
101
|
-
`Running as ${machineIdentityLabel()} — sessions mint automatically; no browser login needed.`,
|
|
102
|
-
),
|
|
103
|
-
);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const existing = loadCachedTokens();
|
|
107
|
-
if (existing && !isExpiring(existing, 120)) {
|
|
108
|
-
const who = peekIdToken(existing.idToken).email ?? "cached session";
|
|
109
|
-
console.log(
|
|
110
|
-
chalk.green(`Already signed in (${who}). Run \`hq auth logout\` to switch accounts.`),
|
|
111
|
-
);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
const tokens = await browserLogin(cognitoConfigForLoginProvider(options.provider));
|
|
116
|
-
const who = peekIdToken(tokens.idToken).email ?? "HQ";
|
|
117
|
-
console.log(chalk.green(`Signed in as ${who}`));
|
|
118
|
-
console.log(
|
|
119
|
-
chalk.dim(` Token cached at ~/.hq/cognito-tokens.json (expires ${tokens.expiresAt})`),
|
|
120
|
-
);
|
|
121
|
-
} catch (err) {
|
|
122
|
-
const callbackPortCollision = isCallbackPortCollision(err);
|
|
123
|
-
const msg =
|
|
124
|
-
callbackPortCollision
|
|
125
|
-
? "Browser-login callback port is already in use."
|
|
126
|
-
: err instanceof CognitoAuthError
|
|
127
|
-
? err.message
|
|
128
|
-
: err instanceof Error
|
|
129
|
-
? err.message
|
|
130
|
-
: String(err);
|
|
131
|
-
console.error(chalk.red(`Login failed: ${msg}`));
|
|
132
|
-
if (callbackPortCollision) {
|
|
133
|
-
console.error(
|
|
134
|
-
chalk.dim(callbackPortCollisionGuidance(DEFAULT_COGNITO.port ?? 8765)),
|
|
135
|
-
);
|
|
136
|
-
} else {
|
|
137
|
-
console.error(
|
|
138
|
-
chalk.dim(
|
|
139
|
-
" If you do not have an account, sign up at https://onboarding.indigo-hq.com",
|
|
140
|
-
),
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
process.exit(1);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
authCmd
|
|
148
|
-
.command("logout")
|
|
149
|
-
.description("Clear the cached HQ Cognito session")
|
|
150
|
-
.action(() => {
|
|
151
|
-
const existing = loadCachedTokens();
|
|
152
|
-
if (!existing) {
|
|
153
|
-
console.log(chalk.yellow("No cached HQ session"));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
clearCachedTokens();
|
|
157
|
-
console.log(chalk.green("Signed out — removed ~/.hq/cognito-tokens.json"));
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
authCmd
|
|
161
|
-
.command("refresh")
|
|
162
|
-
.description(
|
|
163
|
-
"Ensure a valid cached Cognito session (refresh only if expiring; no-op if already valid)",
|
|
164
|
-
)
|
|
165
|
-
.action(async () => {
|
|
166
|
-
const result = await refreshCachedSession();
|
|
167
|
-
if (result.refreshed) {
|
|
168
|
-
console.log(chalk.green("HQ session ensured"));
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
console.error(
|
|
172
|
-
chalk.yellow(`No valid session: ${result.reason ?? "unknown"}`),
|
|
173
|
-
);
|
|
174
|
-
process.exit(1);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
authCmd
|
|
178
|
-
.command("status")
|
|
179
|
-
.description("Show whether a valid HQ session is cached")
|
|
180
|
-
.action(() => {
|
|
181
|
-
const machine = isMachineIdentity();
|
|
182
|
-
const cached = loadCachedTokens();
|
|
183
|
-
if (!cached) {
|
|
184
|
-
if (machine) {
|
|
185
|
-
// No cached session yet, but machine creds mint one on demand —
|
|
186
|
-
// report ready, not signed-out.
|
|
187
|
-
console.log(
|
|
188
|
-
chalk.green(
|
|
189
|
-
`${machineIdentityLabel()} — no cached session yet (mints automatically on first use)`,
|
|
190
|
-
),
|
|
191
|
-
);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
console.log(chalk.yellow("No cached HQ session — run `hq auth login`"));
|
|
195
|
-
process.exit(1);
|
|
196
|
-
}
|
|
197
|
-
const claims = peekIdToken(cached.idToken);
|
|
198
|
-
const who = machine
|
|
199
|
-
? `${machineIdentityLabel()}${claims.entityUid ? ` (${claims.entityUid})` : ""}`
|
|
200
|
-
: claims.email;
|
|
201
|
-
const expiring = isExpiring(cached);
|
|
202
|
-
const label = who ? `${who} — ` : "";
|
|
203
|
-
console.log(
|
|
204
|
-
expiring
|
|
205
|
-
? chalk.yellow(
|
|
206
|
-
`${label}HQ session cached but expiring (expiresAt=${cached.expiresAt})`,
|
|
207
|
-
)
|
|
208
|
-
: chalk.green(
|
|
209
|
-
`${label}HQ session valid (expiresAt=${cached.expiresAt})`,
|
|
210
|
-
),
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `hq billing` (billing.ts).
|
|
3
|
-
*
|
|
4
|
-
* Mirrors company.test.ts: mock ensureCognitoToken + getCompanyUid, spy on
|
|
5
|
-
* global fetch, drive through a Commander program, assert the request shape and
|
|
6
|
-
* rendered output.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { Command } from "commander";
|
|
10
|
-
import {
|
|
11
|
-
afterEach,
|
|
12
|
-
beforeEach,
|
|
13
|
-
describe,
|
|
14
|
-
expect,
|
|
15
|
-
it,
|
|
16
|
-
vi,
|
|
17
|
-
type MockInstance,
|
|
18
|
-
} from "vitest";
|
|
19
|
-
|
|
20
|
-
vi.mock("../utils/cognito-session.js", async (importOriginal) => {
|
|
21
|
-
const original =
|
|
22
|
-
await importOriginal<typeof import("../utils/cognito-session.js")>();
|
|
23
|
-
return {
|
|
24
|
-
...original,
|
|
25
|
-
ensureCognitoToken: vi.fn(async () => "test-token"),
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
vi.mock("../utils/vault-api.js", async (importOriginal) => {
|
|
30
|
-
const original = await importOriginal<typeof import("../utils/vault-api.js")>();
|
|
31
|
-
return {
|
|
32
|
-
...original,
|
|
33
|
-
getCompanyUid: vi.fn(async () => "cmp_acme"),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
38
|
-
import { getCompanyUid } from "../utils/vault-api.js";
|
|
39
|
-
import { registerBillingCommand } from "./billing.js";
|
|
40
|
-
|
|
41
|
-
function jsonResponse(status: number, body: unknown): Response {
|
|
42
|
-
return new Response(JSON.stringify(body), {
|
|
43
|
-
status,
|
|
44
|
-
headers: { "Content-Type": "application/json" },
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let fetchSpy: MockInstance<typeof fetch>;
|
|
49
|
-
let logSpy: MockInstance<typeof console.log>;
|
|
50
|
-
let stdoutSpy: MockInstance<typeof process.stdout.write>;
|
|
51
|
-
const mockEnsureCognitoToken = vi.mocked(ensureCognitoToken);
|
|
52
|
-
const mockGetCompanyUid = vi.mocked(getCompanyUid);
|
|
53
|
-
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
vi.clearAllMocks();
|
|
56
|
-
fetchSpy = vi.spyOn(globalThis, "fetch");
|
|
57
|
-
mockEnsureCognitoToken.mockResolvedValue("test-token");
|
|
58
|
-
mockGetCompanyUid.mockResolvedValue("cmp_acme");
|
|
59
|
-
vi.spyOn(process, "exit").mockImplementation((code?: number) => {
|
|
60
|
-
throw new Error(`process.exit(${code})`);
|
|
61
|
-
});
|
|
62
|
-
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
63
|
-
stdoutSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
|
|
64
|
-
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
afterEach(() => {
|
|
68
|
-
vi.restoreAllMocks();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
function buildProgram(): Command {
|
|
72
|
-
const program = new Command();
|
|
73
|
-
program.name("hq").exitOverride();
|
|
74
|
-
registerBillingCommand(program);
|
|
75
|
-
return program;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function run(args: string[]): Promise<void> {
|
|
79
|
-
await buildProgram().parseAsync(["node", "hq", ...args]);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
describe("hq billing status", () => {
|
|
83
|
-
it("GETs /v1/billing/summary and renders card-on-file", async () => {
|
|
84
|
-
fetchSpy.mockResolvedValueOnce(
|
|
85
|
-
jsonResponse(200, {
|
|
86
|
-
subscriptionStatus: "active",
|
|
87
|
-
defaultPaymentMethod: { present: true, brand: "visa", last4: "4242" },
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
await run(["billing", "--company", "acme", "status"]);
|
|
92
|
-
|
|
93
|
-
const url = String(fetchSpy.mock.calls[0][0]);
|
|
94
|
-
expect(url).toContain("/v1/billing/summary");
|
|
95
|
-
expect(url).toContain("companyUid=cmp_acme");
|
|
96
|
-
const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
|
|
97
|
-
expect(printed).toMatch(/active/);
|
|
98
|
-
expect(printed).toMatch(/visa/);
|
|
99
|
-
expect(printed).toMatch(/4242/);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("flags no card on file", async () => {
|
|
103
|
-
fetchSpy.mockResolvedValueOnce(
|
|
104
|
-
jsonResponse(200, {
|
|
105
|
-
subscriptionStatus: null,
|
|
106
|
-
defaultPaymentMethod: { present: false, brand: null, last4: null },
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
109
|
-
await run(["billing", "--company", "acme", "status"]);
|
|
110
|
-
const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
|
|
111
|
-
expect(printed).toMatch(/no card on file/i);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe("hq billing checkout", () => {
|
|
116
|
-
it("POSTs /v1/billing/checkout/org with companyUid and prints the url", async () => {
|
|
117
|
-
fetchSpy.mockResolvedValueOnce(
|
|
118
|
-
jsonResponse(200, { url: "https://checkout.stripe.com/abc" }),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
await run(["billing", "--company", "acme", "checkout"]);
|
|
122
|
-
|
|
123
|
-
const [url, init] = fetchSpy.mock.calls[0];
|
|
124
|
-
expect(String(url)).toContain("/v1/billing/checkout/org");
|
|
125
|
-
expect(init?.method).toBe("POST");
|
|
126
|
-
expect(JSON.parse(init?.body as string)).toEqual({ companyUid: "cmp_acme" });
|
|
127
|
-
const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
|
|
128
|
-
expect(printed).toContain("https://checkout.stripe.com/abc");
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("POSTs /v1/billing/checkout/person with --personal", async () => {
|
|
132
|
-
fetchSpy.mockResolvedValueOnce(
|
|
133
|
-
jsonResponse(200, { url: "https://checkout.stripe.com/xyz" }),
|
|
134
|
-
);
|
|
135
|
-
await run(["billing", "checkout", "--personal"]);
|
|
136
|
-
const [url, init] = fetchSpy.mock.calls[0];
|
|
137
|
-
expect(String(url)).toContain("/v1/billing/checkout/person");
|
|
138
|
-
expect(init?.method).toBe("POST");
|
|
139
|
-
// Person checkout resolves the payer from the JWT — no companyUid resolution.
|
|
140
|
-
expect(mockGetCompanyUid).not.toHaveBeenCalled();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("emits raw JSON with --json", async () => {
|
|
144
|
-
fetchSpy.mockResolvedValueOnce(
|
|
145
|
-
jsonResponse(200, { url: "https://checkout.stripe.com/j" }),
|
|
146
|
-
);
|
|
147
|
-
await run(["billing", "--company", "acme", "checkout", "--json"]);
|
|
148
|
-
const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("\n");
|
|
149
|
-
expect(printed).toContain("https://checkout.stripe.com/j");
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("exits 1 when the checkout response has no url", async () => {
|
|
153
|
-
fetchSpy.mockResolvedValueOnce(jsonResponse(200, {}));
|
|
154
|
-
await expect(
|
|
155
|
-
run(["billing", "--company", "acme", "checkout"]),
|
|
156
|
-
).rejects.toThrow("process.exit(1)");
|
|
157
|
-
});
|
|
158
|
-
});
|