vouchington-tooling 0.56.0 → 0.58.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/README.md +14 -0
- package/dist/agent-issue-labels/ensure-labels.d.mts +17 -0
- package/dist/agent-issue-labels/ensure-labels.mjs +55 -0
- package/dist/agent-issue-labels/index.d.mts +5 -0
- package/dist/agent-issue-labels/index.mjs +3 -0
- package/dist/agent-issue-labels/label-policy.d.mts +21 -0
- package/dist/agent-issue-labels/label-policy.mjs +67 -0
- package/dist/agent-issue-labels/labels-from-paths.d.mts +9 -0
- package/dist/agent-issue-labels/labels-from-paths.mjs +54 -0
- package/dist/cli/commands/agent-issue-labels.d.mts +2 -0
- package/dist/cli/commands/agent-issue-labels.mjs +17 -0
- package/dist/cli/index.mjs +6 -0
- package/dist/cli/parse-agent-issue-labels.d.mts +19 -0
- package/dist/cli/parse-agent-issue-labels.mjs +70 -0
- package/dist/cli/parse-forwarded-commands.d.mts +3 -0
- package/dist/cli/parse-forwarded-commands.mjs +2 -0
- package/dist/cli/parse.d.mts +5 -1
- package/dist/cli/parse.mjs +3 -0
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +5 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/input-otp-mock/index.d.mts +25 -0
- package/dist/input-otp-mock/index.mjs +34 -0
- package/dist/jsdom-stubs/index.d.mts +12 -0
- package/dist/jsdom-stubs/index.mjs +85 -0
- package/dist/next-navigation-mock/index.d.mts +27 -0
- package/dist/next-navigation-mock/index.mjs +58 -0
- package/dist/workflow-secrets-drift/cli.d.mts +10 -0
- package/dist/workflow-secrets-drift/cli.mjs +73 -0
- package/dist/workflow-secrets-drift/collect.d.mts +10 -0
- package/dist/workflow-secrets-drift/collect.mjs +70 -0
- package/dist/workflow-secrets-drift/drift.d.mts +22 -0
- package/dist/workflow-secrets-drift/drift.mjs +49 -0
- package/dist/workflow-secrets-drift/gh-parse.d.mts +5 -0
- package/dist/workflow-secrets-drift/gh-parse.mjs +41 -0
- package/dist/workflow-secrets-drift/gh.d.mts +4 -0
- package/dist/workflow-secrets-drift/gh.mjs +51 -0
- package/dist/workflow-secrets-drift/index.d.mts +11 -0
- package/dist/workflow-secrets-drift/index.mjs +6 -0
- package/dist/workflow-secrets-drift/inventory.d.mts +10 -0
- package/dist/workflow-secrets-drift/inventory.mjs +78 -0
- package/dist/workflow-secrets-drift/scopes.d.mts +12 -0
- package/dist/workflow-secrets-drift/scopes.mjs +56 -0
- package/dist/workflow-secrets-drift/settle.d.mts +3 -0
- package/dist/workflow-secrets-drift/settle.mjs +19 -0
- package/dist/workflow-secrets-drift/types.d.mts +33 -0
- package/dist/workflow-secrets-drift/types.mjs +1 -0
- package/package.json +39 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/skills/blackboard/SKILL.md +19 -0
- package/skills/github-issue/SKILL.md +12 -0
- package/skills/manifest.json +20 -20
- package/skills/retrospective/SKILL.md +17 -1
- package/skills/retrospective/references/ci-failures.md +48 -0
- package/skills/retrospective/references/sandbox-audit.md +48 -0
- package/skills/retrospective-distill/SKILL.md +11 -3
- package/skills/retrospective-distill/references/issue-body.md +40 -0
- package/skills/stacked-prs/references/gh-stack.md +5 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const SLOT_COUNT = 8;
|
|
2
|
+
/**
|
|
3
|
+
* Factory for `vi.mock(import('input-otp'), inputOtpMockFactory)`. The real library schedules a
|
|
4
|
+
* password-manager timeout that can fire after jsdom teardown ("window is not defined"); this
|
|
5
|
+
* renders a plain text input that forwards `onChange(value)` instead.
|
|
6
|
+
*/
|
|
7
|
+
export async function inputOtpMockFactory() {
|
|
8
|
+
const React = await import('react');
|
|
9
|
+
const OTPInputContext = React.createContext({
|
|
10
|
+
slots: Array.from({ length: SLOT_COUNT }, () => ({
|
|
11
|
+
char: '',
|
|
12
|
+
hasFakeCaret: false,
|
|
13
|
+
isActive: false,
|
|
14
|
+
})),
|
|
15
|
+
});
|
|
16
|
+
const OTPInput = React.forwardRef(function OTPInputMock({ children, maxLength, onChange, containerClassName, pattern, ...rest }, ref) {
|
|
17
|
+
const source = pattern instanceof RegExp ? pattern.source : pattern;
|
|
18
|
+
return React.createElement('div', { 'data-input-otp': true, maxLength, className: containerClassName }, React.createElement('input', {
|
|
19
|
+
type: 'text',
|
|
20
|
+
maxLength,
|
|
21
|
+
ref,
|
|
22
|
+
onChange: (event) => onChange?.(event.target.value),
|
|
23
|
+
pattern: source,
|
|
24
|
+
...rest,
|
|
25
|
+
}), children);
|
|
26
|
+
});
|
|
27
|
+
OTPInput.displayName = 'OTPInput';
|
|
28
|
+
return {
|
|
29
|
+
OTPInput,
|
|
30
|
+
OTPInputContext,
|
|
31
|
+
REGEXP_ONLY_DIGITS: /^\d*$/,
|
|
32
|
+
REGEXP_ONLY_DIGITS_AND_CHARS: /^[a-zA-Z0-9]*$/,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** In-memory `Storage`. Keep the returned object to `clear()` it between tests. */
|
|
2
|
+
export declare function createMemoryStorage(): Storage;
|
|
3
|
+
/**
|
|
4
|
+
* Replaces `localStorage` on `target` (and its `window`, when present) with a fresh in-memory
|
|
5
|
+
* store and returns it so the caller can clear it in `afterEach`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function installMemoryLocalStorage(target?: object): Storage;
|
|
8
|
+
/**
|
|
9
|
+
* Installs no-op `ResizeObserver`, `IntersectionObserver`, `matchMedia` and
|
|
10
|
+
* `HTMLElement.prototype.scrollIntoView` stubs, each only when jsdom leaves it undefined.
|
|
11
|
+
*/
|
|
12
|
+
export declare function installJsdomStubs(target?: object): void;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const noop = () => { };
|
|
2
|
+
class StubResizeObserver {
|
|
3
|
+
observe = noop;
|
|
4
|
+
unobserve = noop;
|
|
5
|
+
disconnect = noop;
|
|
6
|
+
}
|
|
7
|
+
class StubIntersectionObserver {
|
|
8
|
+
observe = noop;
|
|
9
|
+
unobserve = noop;
|
|
10
|
+
disconnect = noop;
|
|
11
|
+
takeRecords() {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function stubMatchMedia(query) {
|
|
16
|
+
return {
|
|
17
|
+
matches: false,
|
|
18
|
+
media: query,
|
|
19
|
+
onchange: null,
|
|
20
|
+
addListener: noop,
|
|
21
|
+
removeListener: noop,
|
|
22
|
+
addEventListener: noop,
|
|
23
|
+
removeEventListener: noop,
|
|
24
|
+
dispatchEvent: () => false,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** In-memory `Storage`. Keep the returned object to `clear()` it between tests. */
|
|
28
|
+
export function createMemoryStorage() {
|
|
29
|
+
const store = new Map();
|
|
30
|
+
return {
|
|
31
|
+
getItem: (key) => store.get(key) ?? null,
|
|
32
|
+
setItem: (key, value) => {
|
|
33
|
+
store.set(key, value);
|
|
34
|
+
},
|
|
35
|
+
removeItem: (key) => {
|
|
36
|
+
store.delete(key);
|
|
37
|
+
},
|
|
38
|
+
clear: () => {
|
|
39
|
+
store.clear();
|
|
40
|
+
},
|
|
41
|
+
get length() {
|
|
42
|
+
return store.size;
|
|
43
|
+
},
|
|
44
|
+
key: (index) => [...store.keys()][index] ?? null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function asTarget(target) {
|
|
48
|
+
return target;
|
|
49
|
+
}
|
|
50
|
+
function define(target, name, value) {
|
|
51
|
+
Object.defineProperty(target, name, { configurable: true, writable: true, value });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Replaces `localStorage` on `target` (and its `window`, when present) with a fresh in-memory
|
|
55
|
+
* store and returns it so the caller can clear it in `afterEach`.
|
|
56
|
+
*/
|
|
57
|
+
export function installMemoryLocalStorage(target = globalThis) {
|
|
58
|
+
const storage = createMemoryStorage();
|
|
59
|
+
define(target, 'localStorage', storage);
|
|
60
|
+
const win = target.window;
|
|
61
|
+
if (win !== undefined && win !== target)
|
|
62
|
+
define(win, 'localStorage', storage);
|
|
63
|
+
return storage;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Installs no-op `ResizeObserver`, `IntersectionObserver`, `matchMedia` and
|
|
67
|
+
* `HTMLElement.prototype.scrollIntoView` stubs, each only when jsdom leaves it undefined.
|
|
68
|
+
*/
|
|
69
|
+
export function installJsdomStubs(target = globalThis) {
|
|
70
|
+
const global = asTarget(target);
|
|
71
|
+
if (global.ResizeObserver === undefined)
|
|
72
|
+
define(global, 'ResizeObserver', StubResizeObserver);
|
|
73
|
+
if (global.IntersectionObserver === undefined) {
|
|
74
|
+
define(global, 'IntersectionObserver', StubIntersectionObserver);
|
|
75
|
+
}
|
|
76
|
+
const win = global.window;
|
|
77
|
+
if (win === undefined)
|
|
78
|
+
return;
|
|
79
|
+
if (win.matchMedia === undefined)
|
|
80
|
+
define(win, 'matchMedia', stubMatchMedia);
|
|
81
|
+
const proto = win.HTMLElement?.prototype;
|
|
82
|
+
if (proto !== undefined && proto.scrollIntoView === undefined) {
|
|
83
|
+
define(proto, 'scrollIntoView', noop);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type NextNavigation = typeof import('next/navigation.js');
|
|
2
|
+
type SearchParamsInit = string | URLSearchParams | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Pass to `vi.mock('next/navigation', () => navMockModule)`. Hooks read the mutable state lazily,
|
|
5
|
+
* so changes made between tests apply on the next render. Import it before the component under
|
|
6
|
+
* test so the factory is initialized when the mock is evaluated.
|
|
7
|
+
*/
|
|
8
|
+
export declare const navMockModule: NextNavigation;
|
|
9
|
+
/**
|
|
10
|
+
* Control object for the shared `navMockModule` singleton: repeated calls share spies and state.
|
|
11
|
+
* Call `reset()` in `beforeEach`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createNavMock(): {
|
|
14
|
+
push: import("vitest").Mock<(...args: unknown[]) => unknown>;
|
|
15
|
+
replace: import("vitest").Mock<(...args: unknown[]) => unknown>;
|
|
16
|
+
refresh: import("vitest").Mock<(...args: unknown[]) => unknown>;
|
|
17
|
+
back: import("vitest").Mock<(...args: unknown[]) => unknown>;
|
|
18
|
+
forward: import("vitest").Mock<(...args: unknown[]) => unknown>;
|
|
19
|
+
prefetch: import("vitest").Mock<(...args: unknown[]) => unknown>;
|
|
20
|
+
/** Accepts the same init forms as `new URLSearchParams()`; `undefined` clears it. */
|
|
21
|
+
setSearchParams(init?: SearchParamsInit): void;
|
|
22
|
+
setPathname(pathname: string): void;
|
|
23
|
+
setParams(params: Record<string, string | string[]>): void;
|
|
24
|
+
/** Restores empty search params, pathname `/`, empty params, and clears spy history. */
|
|
25
|
+
reset(): void;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
const state = {
|
|
3
|
+
// A plain URLSearchParams at runtime; the cast only satisfies the real hook's return type.
|
|
4
|
+
searchParams: new URLSearchParams(),
|
|
5
|
+
pathname: '/',
|
|
6
|
+
params: {},
|
|
7
|
+
};
|
|
8
|
+
const push = vi.fn();
|
|
9
|
+
const replace = vi.fn();
|
|
10
|
+
const refresh = vi.fn();
|
|
11
|
+
const back = vi.fn();
|
|
12
|
+
const forward = vi.fn();
|
|
13
|
+
const prefetch = vi.fn();
|
|
14
|
+
const spies = [push, replace, refresh, back, forward, prefetch];
|
|
15
|
+
const router = { push, replace, refresh, back, forward, prefetch };
|
|
16
|
+
/**
|
|
17
|
+
* Pass to `vi.mock('next/navigation', () => navMockModule)`. Hooks read the mutable state lazily,
|
|
18
|
+
* so changes made between tests apply on the next render. Import it before the component under
|
|
19
|
+
* test so the factory is initialized when the mock is evaluated.
|
|
20
|
+
*/
|
|
21
|
+
export const navMockModule = {
|
|
22
|
+
useRouter: () => router,
|
|
23
|
+
useSearchParams: () => state.searchParams,
|
|
24
|
+
usePathname: () => state.pathname,
|
|
25
|
+
useParams: () => state.params,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Control object for the shared `navMockModule` singleton: repeated calls share spies and state.
|
|
29
|
+
* Call `reset()` in `beforeEach`.
|
|
30
|
+
*/
|
|
31
|
+
export function createNavMock() {
|
|
32
|
+
return {
|
|
33
|
+
push,
|
|
34
|
+
replace,
|
|
35
|
+
refresh,
|
|
36
|
+
back,
|
|
37
|
+
forward,
|
|
38
|
+
prefetch,
|
|
39
|
+
/** Accepts the same init forms as `new URLSearchParams()`; `undefined` clears it. */
|
|
40
|
+
setSearchParams(init) {
|
|
41
|
+
state.searchParams = new URLSearchParams(init);
|
|
42
|
+
},
|
|
43
|
+
setPathname(pathname) {
|
|
44
|
+
state.pathname = pathname;
|
|
45
|
+
},
|
|
46
|
+
setParams(params) {
|
|
47
|
+
state.params = params;
|
|
48
|
+
},
|
|
49
|
+
/** Restores empty search params, pathname `/`, empty params, and clears spy history. */
|
|
50
|
+
reset() {
|
|
51
|
+
state.searchParams = new URLSearchParams();
|
|
52
|
+
state.pathname = '/';
|
|
53
|
+
state.params = {};
|
|
54
|
+
for (const spy of spies)
|
|
55
|
+
spy.mockReset();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkflowSecretInventory, WorkflowSecretsDependencies } from './types.mts';
|
|
2
|
+
export declare const USAGE: string;
|
|
3
|
+
export interface VerifyWorkflowSecretsOptions {
|
|
4
|
+
dependencies?: WorkflowSecretsDependencies;
|
|
5
|
+
output?: Pick<Console, 'error' | 'log'>;
|
|
6
|
+
/** Skips loading `--inventory` when supplied. */
|
|
7
|
+
inventory?: WorkflowSecretInventory;
|
|
8
|
+
cwd?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function runVerifyWorkflowSecretsCli(argv: readonly string[], options?: VerifyWorkflowSecretsOptions): Promise<number>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { collectLiveSecretNames } from "./collect.mjs";
|
|
3
|
+
import { diffAgainstInventory, formatDrift, missingConfirmedSecrets, unconfirmedNewlyProvisioned, } from "./drift.mjs";
|
|
4
|
+
import { createGhDependencies } from "./gh.mjs";
|
|
5
|
+
import { DEFAULT_INVENTORY_EXPORT, DEFAULT_INVENTORY_PATH, loadInventory, normalizeInventory, } from "./inventory.mjs";
|
|
6
|
+
import { requiredEnvironmentNames, requiredSecretScopeViolations } from "./scopes.mjs";
|
|
7
|
+
import { errorMessage } from "./settle.mjs";
|
|
8
|
+
export const USAGE = 'Usage: vouchington verify-workflow-secrets [--repo <owner/repo>] [--confirm <name1,name2,...>] ' +
|
|
9
|
+
'[--inventory <module>] [--export <name>] [--branch <name>]';
|
|
10
|
+
const splitNames = (raw) => (raw ?? '')
|
|
11
|
+
.split(',')
|
|
12
|
+
.map((name) => name.trim().toUpperCase())
|
|
13
|
+
.filter((name) => name.length > 0);
|
|
14
|
+
export async function runVerifyWorkflowSecretsCli(argv, options = {}) {
|
|
15
|
+
const { output = console, dependencies = createGhDependencies() } = options;
|
|
16
|
+
let values;
|
|
17
|
+
try {
|
|
18
|
+
;
|
|
19
|
+
({ values } = parseArgs({
|
|
20
|
+
args: [...argv],
|
|
21
|
+
options: {
|
|
22
|
+
repo: { type: 'string' },
|
|
23
|
+
confirm: { type: 'string' },
|
|
24
|
+
inventory: { type: 'string', default: DEFAULT_INVENTORY_PATH },
|
|
25
|
+
export: { type: 'string', default: DEFAULT_INVENTORY_EXPORT },
|
|
26
|
+
branch: { type: 'string', default: 'main' },
|
|
27
|
+
},
|
|
28
|
+
strict: true,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
output.error(`${USAGE}\n${errorMessage(err)}`);
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
const confirmNames = splitNames(values.confirm);
|
|
36
|
+
const emptyOption = ['repo', 'inventory', 'export', 'branch'].find((key) => values[key] !== undefined && values[key].trim() === '');
|
|
37
|
+
if (emptyOption !== undefined || (values.confirm !== undefined && confirmNames.length === 0)) {
|
|
38
|
+
output.error(`${USAGE}\n--${emptyOption ?? 'confirm'} requires a non-empty value`);
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const inventory = normalizeInventory(options.inventory ??
|
|
43
|
+
(await loadInventory(values.inventory, values.export, options.cwd ?? process.cwd())));
|
|
44
|
+
const repo = values.repo ?? (await dependencies.resolveRepo());
|
|
45
|
+
const live = await collectLiveSecretNames(repo, dependencies, requiredEnvironmentNames(inventory));
|
|
46
|
+
const drift = diffAgainstInventory(inventory, live.names, live.warnings);
|
|
47
|
+
output.log(formatDrift(drift));
|
|
48
|
+
const scopeViolations = requiredSecretScopeViolations(inventory, {
|
|
49
|
+
...live,
|
|
50
|
+
deploymentBranch: values.branch,
|
|
51
|
+
});
|
|
52
|
+
if (scopeViolations.length > 0) {
|
|
53
|
+
output.log(`Secret scope violations:\n${scopeViolations.map((value) => ` - ${value}`).join('\n')}`);
|
|
54
|
+
}
|
|
55
|
+
const missingConfirmed = missingConfirmedSecrets(confirmNames, live.names);
|
|
56
|
+
if (confirmNames.length > 0) {
|
|
57
|
+
output.log(missingConfirmed.length > 0
|
|
58
|
+
? `--confirm expected these secret(s) to be live, but gh does not see them: ${missingConfirmed.join(', ')}`
|
|
59
|
+
: `Confirmed all ${confirmNames.length} --confirm secret(s) are live.`);
|
|
60
|
+
}
|
|
61
|
+
const failed = unconfirmedNewlyProvisioned(drift, confirmNames).length > 0 ||
|
|
62
|
+
drift.notActuallyProvisioned.length > 0 ||
|
|
63
|
+
drift.accidentallyProvisioned.length > 0 ||
|
|
64
|
+
drift.warnings.length > 0 ||
|
|
65
|
+
scopeViolations.length > 0 ||
|
|
66
|
+
missingConfirmed.length > 0;
|
|
67
|
+
return failed ? 1 : 0;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
output.error(`verify-workflow-secrets failed: ${errorMessage(err)}`);
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EnvironmentDeploymentBranchPolicy, WorkflowSecretsDependencies } from './types.mts';
|
|
2
|
+
export interface LiveSecretNames {
|
|
3
|
+
names: Set<string>;
|
|
4
|
+
repositoryNames: Set<string>;
|
|
5
|
+
organizationNames: Set<string>;
|
|
6
|
+
environmentNames: Map<string, Set<string>>;
|
|
7
|
+
environmentDeploymentBranchPolicies: Map<string, EnvironmentDeploymentBranchPolicy>;
|
|
8
|
+
warnings: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function collectLiveSecretNames(repo: string, dependencies: WorkflowSecretsDependencies, requiredPolicyEnvironments: ReadonlySet<string>): Promise<LiveSecretNames>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { errorMessage, settleLimited } from "./settle.mjs";
|
|
2
|
+
const QUERY_CONCURRENCY = 5;
|
|
3
|
+
/** GitHub stores secret names upper-case and compares them case-insensitively. */
|
|
4
|
+
const upperCased = (names) => new Set(names.map((name) => name.toUpperCase()));
|
|
5
|
+
async function collectOrganizationNames(repo, dependencies, warnings) {
|
|
6
|
+
try {
|
|
7
|
+
const ownerType = await dependencies.listRepositoryOwnerType(repo);
|
|
8
|
+
if (ownerType !== 'Organization' && ownerType !== 'User') {
|
|
9
|
+
throw new Error(`unexpected repository owner type: ${ownerType}`);
|
|
10
|
+
}
|
|
11
|
+
if (ownerType === 'User')
|
|
12
|
+
return new Set();
|
|
13
|
+
return upperCased(await dependencies.listRepositoryOrganizationSecretNames(repo));
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
warnings.push(`Could not list organization secrets for ${repo}: ${errorMessage(err)}`);
|
|
17
|
+
return new Set();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function collectEnvironmentNames(repo, dependencies, warnings) {
|
|
21
|
+
let environments = [];
|
|
22
|
+
try {
|
|
23
|
+
environments = await dependencies.listEnvironmentNames(repo);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
warnings.push(`Could not list deployment environments for ${repo}: ${errorMessage(err)}`);
|
|
27
|
+
}
|
|
28
|
+
const results = await settleLimited(environments, QUERY_CONCURRENCY, (environment) => dependencies.listEnvironmentSecretNames(repo, environment));
|
|
29
|
+
const byEnvironment = new Map();
|
|
30
|
+
results.forEach((result, index) => {
|
|
31
|
+
if (result.status === 'fulfilled') {
|
|
32
|
+
byEnvironment.set(environments[index].toLowerCase(), upperCased(result.value));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
warnings.push(`Could not list secrets for environment "${environments[index]}": ${errorMessage(result.reason)}`);
|
|
36
|
+
});
|
|
37
|
+
return byEnvironment;
|
|
38
|
+
}
|
|
39
|
+
async function collectBranchPolicies(repo, environments, dependencies, warnings) {
|
|
40
|
+
const names = [...environments];
|
|
41
|
+
const results = await settleLimited(names, QUERY_CONCURRENCY, (environment) => dependencies.getEnvironmentDeploymentBranchPolicy(repo, environment));
|
|
42
|
+
const policies = new Map();
|
|
43
|
+
results.forEach((result, index) => {
|
|
44
|
+
if (result.status === 'fulfilled') {
|
|
45
|
+
policies.set(names[index], result.value);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
warnings.push(`Could not list deployment branch policy for environment "${names[index]}": ${errorMessage(result.reason)}`);
|
|
49
|
+
});
|
|
50
|
+
return policies;
|
|
51
|
+
}
|
|
52
|
+
export async function collectLiveSecretNames(repo, dependencies, requiredPolicyEnvironments) {
|
|
53
|
+
const warnings = [];
|
|
54
|
+
const repositoryNames = upperCased(await dependencies.listRepoSecretNames(repo));
|
|
55
|
+
const organizationNames = await collectOrganizationNames(repo, dependencies, warnings);
|
|
56
|
+
const environmentNames = await collectEnvironmentNames(repo, dependencies, warnings);
|
|
57
|
+
const environmentDeploymentBranchPolicies = await collectBranchPolicies(repo, requiredPolicyEnvironments, dependencies, warnings);
|
|
58
|
+
const names = new Set([...repositoryNames, ...organizationNames]);
|
|
59
|
+
for (const scoped of environmentNames.values())
|
|
60
|
+
for (const name of scoped)
|
|
61
|
+
names.add(name);
|
|
62
|
+
return {
|
|
63
|
+
names,
|
|
64
|
+
repositoryNames,
|
|
65
|
+
organizationNames,
|
|
66
|
+
environmentNames,
|
|
67
|
+
environmentDeploymentBranchPolicies,
|
|
68
|
+
warnings,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { WorkflowSecretInventory } from './types.mts';
|
|
2
|
+
export interface SecretDrift {
|
|
3
|
+
/** `provisioned: false` in the inventory, but live: flip the flag to true. */
|
|
4
|
+
readonly newlyProvisioned: string[];
|
|
5
|
+
/** `provisioned: true` in the inventory, but not live: investigate. */
|
|
6
|
+
readonly notActuallyProvisioned: string[];
|
|
7
|
+
/** `neverProvision: true` in the inventory, but live anyway: delete the live secret. */
|
|
8
|
+
readonly accidentallyProvisioned: string[];
|
|
9
|
+
/** Live secret with no inventory entry: informational, not a drift failure. */
|
|
10
|
+
readonly unreferenced: string[];
|
|
11
|
+
/** Reads the secret store could not complete (permissions, deleted mid-run, etc). */
|
|
12
|
+
readonly warnings: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function diffAgainstInventory(inventory: WorkflowSecretInventory, liveNames: ReadonlySet<string>, warnings: readonly string[]): SecretDrift;
|
|
15
|
+
/** `confirmNames` entries that are not live: the operator's post-provisioning checklist fell short. */
|
|
16
|
+
export declare function missingConfirmedSecrets(confirmNames: readonly string[], liveNames: ReadonlySet<string>): string[];
|
|
17
|
+
/**
|
|
18
|
+
* `drift.newlyProvisioned` names not covered by `--confirm`. A confirmed name is expected to still
|
|
19
|
+
* be `provisioned: false` until a follow-up edit, so only other newly-provisioned names are drift.
|
|
20
|
+
*/
|
|
21
|
+
export declare function unconfirmedNewlyProvisioned(drift: SecretDrift, confirmNames: readonly string[]): string[];
|
|
22
|
+
export declare function formatDrift(drift: SecretDrift): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function diffAgainstInventory(inventory, liveNames, warnings) {
|
|
2
|
+
const newlyProvisioned = [];
|
|
3
|
+
const notActuallyProvisioned = [];
|
|
4
|
+
const accidentallyProvisioned = [];
|
|
5
|
+
for (const [name, entry] of Object.entries(inventory)) {
|
|
6
|
+
if (entry.neverProvision) {
|
|
7
|
+
if (liveNames.has(name))
|
|
8
|
+
accidentallyProvisioned.push(name);
|
|
9
|
+
}
|
|
10
|
+
else if (!entry.provisioned && liveNames.has(name))
|
|
11
|
+
newlyProvisioned.push(name);
|
|
12
|
+
else if (entry.provisioned && !liveNames.has(name))
|
|
13
|
+
notActuallyProvisioned.push(name);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
newlyProvisioned: newlyProvisioned.toSorted(),
|
|
17
|
+
notActuallyProvisioned: notActuallyProvisioned.toSorted(),
|
|
18
|
+
accidentallyProvisioned: accidentallyProvisioned.toSorted(),
|
|
19
|
+
unreferenced: [...liveNames].filter((name) => !Object.hasOwn(inventory, name)).toSorted(),
|
|
20
|
+
warnings: [...warnings],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** `confirmNames` entries that are not live: the operator's post-provisioning checklist fell short. */
|
|
24
|
+
export function missingConfirmedSecrets(confirmNames, liveNames) {
|
|
25
|
+
return confirmNames.filter((name) => !liveNames.has(name));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `drift.newlyProvisioned` names not covered by `--confirm`. A confirmed name is expected to still
|
|
29
|
+
* be `provisioned: false` until a follow-up edit, so only other newly-provisioned names are drift.
|
|
30
|
+
*/
|
|
31
|
+
export function unconfirmedNewlyProvisioned(drift, confirmNames) {
|
|
32
|
+
const confirmed = new Set(confirmNames);
|
|
33
|
+
return drift.newlyProvisioned.filter((name) => !confirmed.has(name));
|
|
34
|
+
}
|
|
35
|
+
function section(title, names) {
|
|
36
|
+
return names.length === 0 ? [] : [title, ...names.map((name) => ` - ${name}`)];
|
|
37
|
+
}
|
|
38
|
+
export function formatDrift(drift) {
|
|
39
|
+
const lines = [
|
|
40
|
+
...section('Now provisioned but still marked `provisioned: false` (flip it in the inventory):', drift.newlyProvisioned),
|
|
41
|
+
...section('Marked `provisioned: true` but not visible to this gh session (deleted, renamed, or a token-scope gap; verify before editing):', drift.notActuallyProvisioned),
|
|
42
|
+
...section('Marked `neverProvision: true` but provisioned live anyway (delete the live secret, do not flip `provisioned`):', drift.accidentallyProvisioned),
|
|
43
|
+
...section('Provisioned but not in the inventory (fine if consumed outside workflows, e.g. Dependabot/Codespaces):', drift.unreferenced),
|
|
44
|
+
...drift.warnings.map((warning) => `Warning: ${warning}`),
|
|
45
|
+
];
|
|
46
|
+
if (lines.length === 0)
|
|
47
|
+
lines.push('The inventory matches the live secret store. No drift.');
|
|
48
|
+
return `${lines.join('\n')}\n`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DeploymentBranchRule, EnvironmentDeploymentBranchPolicy } from './types.mts';
|
|
2
|
+
export declare function outputNames(stdout: string): string[];
|
|
3
|
+
export declare function parseSecretNames(stdout: string): string[];
|
|
4
|
+
export declare function parseDeploymentBranchPolicy(stdout: string): Omit<EnvironmentDeploymentBranchPolicy, 'deploymentBranchRules'>;
|
|
5
|
+
export declare function parseDeploymentBranchRules(stdout: string): DeploymentBranchRule[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
export function outputNames(stdout) {
|
|
3
|
+
return stdout
|
|
4
|
+
.split('\n')
|
|
5
|
+
.map((line) => line.trim())
|
|
6
|
+
.filter((line) => line.length > 0);
|
|
7
|
+
}
|
|
8
|
+
export function parseSecretNames(stdout) {
|
|
9
|
+
return JSON.parse(stdout).map((entry) => entry.name);
|
|
10
|
+
}
|
|
11
|
+
export function parseDeploymentBranchPolicy(stdout) {
|
|
12
|
+
const parsed = JSON.parse(stdout);
|
|
13
|
+
if (!isRecord(parsed) ||
|
|
14
|
+
typeof parsed.protected_branches !== 'boolean' ||
|
|
15
|
+
typeof parsed.custom_branch_policies !== 'boolean') {
|
|
16
|
+
throw new Error('unexpected deployment branch policy metadata');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
protectedBranchesEnabled: parsed.protected_branches,
|
|
20
|
+
customBranchPoliciesEnabled: parsed.custom_branch_policies,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function parseDeploymentBranchRules(stdout) {
|
|
24
|
+
const parsed = JSON.parse(stdout);
|
|
25
|
+
const invalid = new Error('unexpected deployment branch policy');
|
|
26
|
+
if (!isRecord(parsed))
|
|
27
|
+
throw invalid;
|
|
28
|
+
const { total_count, branch_policies } = parsed;
|
|
29
|
+
if (!Number.isSafeInteger(total_count) ||
|
|
30
|
+
!Array.isArray(branch_policies) ||
|
|
31
|
+
branch_policies.length > 2 ||
|
|
32
|
+
branch_policies.length !== total_count) {
|
|
33
|
+
throw invalid;
|
|
34
|
+
}
|
|
35
|
+
return branch_policies.map((rule) => {
|
|
36
|
+
if (!isRecord(rule) || typeof rule.name !== 'string' || typeof rule.type !== 'string') {
|
|
37
|
+
throw invalid;
|
|
38
|
+
}
|
|
39
|
+
return { name: rule.name, type: rule.type };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type RunTextCommand } from '../gh-cli/exec.mts';
|
|
2
|
+
import type { WorkflowSecretsDependencies } from './types.mts';
|
|
3
|
+
/** Builds the live reads on top of an injectable `gh` runner (argv in, stdout out). */
|
|
4
|
+
export declare function createGhDependencies(run?: RunTextCommand): WorkflowSecretsDependencies;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { runGh } from "../gh-cli/exec.mjs";
|
|
2
|
+
import { outputNames, parseDeploymentBranchPolicy, parseDeploymentBranchRules, parseSecretNames, } from "./gh-parse.mjs";
|
|
3
|
+
/** Builds the live reads on top of an injectable `gh` runner (argv in, stdout out). */
|
|
4
|
+
export function createGhDependencies(run = runGh) {
|
|
5
|
+
return {
|
|
6
|
+
resolveRepo: async () => (await run(['repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner'])).trim(),
|
|
7
|
+
listRepoSecretNames: async (repo) => parseSecretNames(await run(['secret', 'list', '-R', repo, '--json', 'name'])),
|
|
8
|
+
listRepositoryOwnerType: async (repo) => (await run(['api', `repos/${repo}`, '--jq', '.owner.type'])).trim(),
|
|
9
|
+
listRepositoryOrganizationSecretNames: async (repo) => outputNames(await run([
|
|
10
|
+
'api',
|
|
11
|
+
`repos/${repo}/actions/organization-secrets`,
|
|
12
|
+
'--paginate',
|
|
13
|
+
'--jq',
|
|
14
|
+
'.secrets[].name',
|
|
15
|
+
])),
|
|
16
|
+
listEnvironmentNames: async (repo) => outputNames(await run([
|
|
17
|
+
'api',
|
|
18
|
+
`repos/${repo}/environments`,
|
|
19
|
+
'--paginate',
|
|
20
|
+
'--jq',
|
|
21
|
+
'.environments[].name',
|
|
22
|
+
])),
|
|
23
|
+
listEnvironmentSecretNames: async (repo, environment) => outputNames(await run([
|
|
24
|
+
'api',
|
|
25
|
+
`repos/${repo}/environments/${encodeURIComponent(environment)}/secrets`,
|
|
26
|
+
'--paginate',
|
|
27
|
+
'--jq',
|
|
28
|
+
'.secrets[].name',
|
|
29
|
+
])),
|
|
30
|
+
getEnvironmentDeploymentBranchPolicy: async (repo, environment) => {
|
|
31
|
+
const endpoint = `repos/${repo}/environments/${encodeURIComponent(environment)}`;
|
|
32
|
+
const policy = parseDeploymentBranchPolicy(await run(['api', endpoint, '--jq', '.deployment_branch_policy']));
|
|
33
|
+
if (!policy.customBranchPoliciesEnabled || policy.protectedBranchesEnabled) {
|
|
34
|
+
return { ...policy, deploymentBranchRules: [] };
|
|
35
|
+
}
|
|
36
|
+
const rules = await run([
|
|
37
|
+
'api',
|
|
38
|
+
'-X',
|
|
39
|
+
'GET',
|
|
40
|
+
`${endpoint}/deployment-branch-policies`,
|
|
41
|
+
'-F',
|
|
42
|
+
'per_page=2',
|
|
43
|
+
'-F',
|
|
44
|
+
'page=1',
|
|
45
|
+
'--jq',
|
|
46
|
+
'{total_count, branch_policies: [.branch_policies[] | {name, type}]}',
|
|
47
|
+
]);
|
|
48
|
+
return { ...policy, deploymentBranchRules: parseDeploymentBranchRules(rules) };
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { runVerifyWorkflowSecretsCli, USAGE } from './cli.mts';
|
|
2
|
+
export type { VerifyWorkflowSecretsOptions } from './cli.mts';
|
|
3
|
+
export { collectLiveSecretNames } from './collect.mts';
|
|
4
|
+
export type { LiveSecretNames } from './collect.mts';
|
|
5
|
+
export { diffAgainstInventory, formatDrift, missingConfirmedSecrets, unconfirmedNewlyProvisioned, } from './drift.mts';
|
|
6
|
+
export type { SecretDrift } from './drift.mts';
|
|
7
|
+
export { createGhDependencies } from './gh.mts';
|
|
8
|
+
export { DEFAULT_INVENTORY_EXPORT, DEFAULT_INVENTORY_PATH, loadInventory, normalizeInventory, } from './inventory.mts';
|
|
9
|
+
export { requiredEnvironmentNames, requiredSecretScopeViolations } from './scopes.mts';
|
|
10
|
+
export type { ScopeInput } from './scopes.mts';
|
|
11
|
+
export type { DeploymentBranchRule, EnvironmentDeploymentBranchPolicy, WorkflowSecretInventory, WorkflowSecretInventoryEntry, WorkflowSecretsDependencies, } from './types.mts';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { runVerifyWorkflowSecretsCli, USAGE } from "./cli.mjs";
|
|
2
|
+
export { collectLiveSecretNames } from "./collect.mjs";
|
|
3
|
+
export { diffAgainstInventory, formatDrift, missingConfirmedSecrets, unconfirmedNewlyProvisioned, } from "./drift.mjs";
|
|
4
|
+
export { createGhDependencies } from "./gh.mjs";
|
|
5
|
+
export { DEFAULT_INVENTORY_EXPORT, DEFAULT_INVENTORY_PATH, loadInventory, normalizeInventory, } from "./inventory.mjs";
|
|
6
|
+
export { requiredEnvironmentNames, requiredSecretScopeViolations } from "./scopes.mjs";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkflowSecretInventory } from './types.mts';
|
|
2
|
+
export declare const DEFAULT_INVENTORY_PATH = ".github/workflows/workflow-secrets-inventory.mts";
|
|
3
|
+
export declare const DEFAULT_INVENTORY_EXPORT = "SECRET_INVENTORY";
|
|
4
|
+
/**
|
|
5
|
+
* GitHub stores secret names upper-case and treats environment names case-insensitively, so
|
|
6
|
+
* names are compared as upper-case secrets and lower-case environments.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeInventory(inventory: WorkflowSecretInventory): WorkflowSecretInventory;
|
|
9
|
+
/** Loads the named export of an inventory module (resolved against `cwd`) and checks its shape. */
|
|
10
|
+
export declare function loadInventory(modulePath: string, exportName: string, cwd?: string): Promise<WorkflowSecretInventory>;
|