@patronage/factory-ci 1.0.0-alpha.4 → 1.0.0-alpha.41
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 +713 -11
- package/dist/.build-fingerprint.json +3 -0
- package/dist/alchemy/index.d.ts +1174 -0
- package/dist/alchemy/index.js +2142 -0
- package/dist/bundle-alchemy-entry-CT5hCphA.js +112 -0
- package/dist/execute-alchemy-entry-B0lBN-YZ.js +160 -0
- package/dist/execute-alchemy-entry-B397GSk5.d.ts +134 -0
- package/dist/index.d.ts +1218 -93
- package/dist/index.js +2841 -333
- package/package.json +28 -10
- package/src/actions.ts +13 -0
- package/src/alchemy/child-diagnostics.ts +148 -0
- package/src/alchemy/credential-preflight.ts +428 -0
- package/src/alchemy/destroy-postcondition.ts +103 -0
- package/src/alchemy/evaluate-stack.ts +153 -0
- package/src/alchemy/first-deploy-authorization.ts +194 -0
- package/src/alchemy/index.ts +144 -0
- package/src/alchemy/lifecycle-failure.ts +174 -0
- package/src/alchemy/lifecycle.ts +1330 -0
- package/src/alchemy/local-emulation.ts +89 -0
- package/src/alchemy/plan-effects.ts +510 -0
- package/src/alchemy/retained-identity.ts +248 -0
- package/src/alchemy/secret-name-policy.ts +96 -0
- package/src/alchemy/stage-policy.ts +269 -0
- package/src/alchemy/state-tree.ts +168 -0
- package/src/alchemy/url-implies-auth.ts +264 -0
- package/src/alchemy-baseline.ts +75 -0
- package/src/bundle-alchemy-entry.ts +5 -0
- package/src/candidate-impact-workflow.ts +110 -0
- package/src/candidate-lifecycle.ts +29 -0
- package/src/cursor-oidc.ts +33 -0
- package/src/execute-alchemy-entry.ts +128 -8
- package/src/factory-workflow.ts +83 -40
- package/src/github-app-token.ts +131 -22
- package/src/github-transport.ts +186 -0
- package/src/impact-demand-condition.ts +67 -0
- package/src/index.ts +174 -0
- package/src/lifecycle-contract-lane.ts +113 -0
- package/src/merge-freeze-job.ts +253 -0
- package/src/pinned-action.ts +30 -0
- package/src/pr-status-hud-workflow.ts +96 -0
- package/src/preview-cleanup-topology.ts +115 -0
- package/src/preview-proof-inventory.ts +1092 -0
- package/src/preview-proof-lifecycle.ts +328 -0
- package/src/preview-receipt-workflow.ts +83 -0
- package/src/production-impact-workflow.ts +181 -0
- package/src/proof-reuse-gate.ts +297 -63
- package/src/proof-reuse-presentation.ts +131 -0
- package/src/push-identity-workflow.ts +463 -0
- package/src/runnable-cli.ts +27 -0
- package/src/verify-runner-policy.ts +290 -0
- package/src/vitest-profile-reader.test.ts +208 -0
- package/src/vitest-profile-reader.ts +225 -0
- package/src/vitest-profile.ts +631 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One GitHub JSON request with bounded transport retries (#830, #923).
|
|
5
|
+
*
|
|
6
|
+
* Both GitHub callers in this package share this primitive: the preview-proof
|
|
7
|
+
* inventory and the GitHub App token mint. Each attempt gets a fresh timeout
|
|
8
|
+
* signal. A transport failure — a rejected fetch, a timeout, a transient HTTP
|
|
9
|
+
* status, or a body that dies mid-read — retries with doubling backoff and
|
|
10
|
+
* exhausts into the caller's transport error. A permanent HTTP refusal throws
|
|
11
|
+
* the caller's refusal error on its first response.
|
|
12
|
+
*
|
|
13
|
+
* Retrying a write is safe here: check-run payloads are idempotent per stack
|
|
14
|
+
* and stage, and a token mint issues a fresh token per call.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const GITHUB_API_VERSION = "2022-11-28";
|
|
18
|
+
/**
|
|
19
|
+
* Default total transport attempts per request, the first one included. A
|
|
20
|
+
* caller whose request has a fallback overrides it with 1 (#938).
|
|
21
|
+
*/
|
|
22
|
+
const TRANSPORT_RETRY_ATTEMPTS = 3;
|
|
23
|
+
/** Delay before the first retry; each further retry doubles it. */
|
|
24
|
+
const TRANSPORT_RETRY_BACKOFF_MS = 500;
|
|
25
|
+
|
|
26
|
+
type TransportWait = (ms: number) => Promise<void>;
|
|
27
|
+
|
|
28
|
+
const defaultTransportWait: TransportWait = (ms) => sleep(ms);
|
|
29
|
+
|
|
30
|
+
let transportWait: TransportWait = defaultTransportWait;
|
|
31
|
+
|
|
32
|
+
/** Package-test seam. Not re-exported from `index.ts`. */
|
|
33
|
+
export const setGithubTransportWaitForTests = (next?: TransportWait): void => {
|
|
34
|
+
transportWait = next ?? defaultTransportWait;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Bounded transport retries could not reach the GitHub App endpoint (#923).
|
|
39
|
+
* The reason is credential-free, so it is safe to log. Re-exported from
|
|
40
|
+
* `github-app-token.ts`, which owns the mint surface.
|
|
41
|
+
*/
|
|
42
|
+
export class GitHubAppTokenTransportError extends Error {
|
|
43
|
+
/** How many transport attempts were made before giving up. */
|
|
44
|
+
readonly attempts: number;
|
|
45
|
+
/** The last transient HTTP status, when the server answered at all. */
|
|
46
|
+
readonly status?: number;
|
|
47
|
+
|
|
48
|
+
constructor(reason: string, attempts: number, status?: number) {
|
|
49
|
+
super(
|
|
50
|
+
`GitHub App token transport failed after ${attempts} attempt(s): ${reason}`
|
|
51
|
+
);
|
|
52
|
+
this.name = "GitHubAppTokenTransportError";
|
|
53
|
+
this.attempts = attempts;
|
|
54
|
+
if (status !== undefined) {
|
|
55
|
+
this.status = status;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** What the last attempt failed with, in a form safe to put in a message. */
|
|
61
|
+
interface GithubTransportFailure {
|
|
62
|
+
reason: string;
|
|
63
|
+
status?: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface GithubJsonOptions {
|
|
67
|
+
/**
|
|
68
|
+
* Total attempts, the first one included. Defaults to
|
|
69
|
+
* `TRANSPORT_RETRY_ATTEMPTS`. A caller whose request is best-effort and has
|
|
70
|
+
* its own fallback passes 1: retrying against a deliberately short timeout
|
|
71
|
+
* only delays the fallback it already has (#938). Values below 1 are read
|
|
72
|
+
* as 1, because one attempt is always made.
|
|
73
|
+
*/
|
|
74
|
+
attempts?: number;
|
|
75
|
+
body?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Send `Connection: close`. A pooled keep-alive socket that outlived
|
|
78
|
+
* GitHub's idle timeout dies with `write EPIPE` on the next request, so a
|
|
79
|
+
* caller that leaves multi-minute gaps between requests opts out of reuse.
|
|
80
|
+
*/
|
|
81
|
+
closeConnection?: boolean;
|
|
82
|
+
fetch: typeof fetch;
|
|
83
|
+
method: "GET" | "PATCH" | "POST";
|
|
84
|
+
timeoutMs: number;
|
|
85
|
+
token: string;
|
|
86
|
+
url: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface GithubJsonErrors {
|
|
90
|
+
/** GitHub judged the request. Thrown on the first response, never retried. */
|
|
91
|
+
refusal: (status: number, statusText: string) => Error;
|
|
92
|
+
/** Every attempt failed in transport. Thrown after the last one. */
|
|
93
|
+
transport: (failure: GithubTransportFailure, attempts: number) => Error;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type TransportOutcome =
|
|
97
|
+
| { ok: true; value: unknown }
|
|
98
|
+
| ({ ok: false } & GithubTransportFailure);
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Transient statuses are the ones where GitHub never judged the content — a
|
|
102
|
+
* request timeout (408), a rate limit (429), or the server failing (5xx) — so
|
|
103
|
+
* the same bytes can still succeed. Every other non-2xx is GitHub refusing
|
|
104
|
+
* this request and repeats on retry.
|
|
105
|
+
*/
|
|
106
|
+
const isTransientStatus = (status: number): boolean =>
|
|
107
|
+
status === 408 || status === 429 || status >= 500;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A bounded, credential-free description of a transport failure. The raw
|
|
111
|
+
* error may retain the request and its `Authorization` header; only the name
|
|
112
|
+
* and a truncated message survive.
|
|
113
|
+
*/
|
|
114
|
+
const boundedTransportReason = (error: unknown): string =>
|
|
115
|
+
error instanceof Error
|
|
116
|
+
? `${error.name}: ${error.message}`.slice(0, 200)
|
|
117
|
+
: "unknown transport error";
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* One attempt with a fresh timeout signal. A transport failure is reported as
|
|
121
|
+
* an outcome so the caller can retry; a permanent HTTP refusal throws here.
|
|
122
|
+
*/
|
|
123
|
+
const githubJsonAttempt = async (
|
|
124
|
+
options: GithubJsonOptions,
|
|
125
|
+
errors: GithubJsonErrors
|
|
126
|
+
): Promise<TransportOutcome> => {
|
|
127
|
+
let response: Response;
|
|
128
|
+
try {
|
|
129
|
+
response = await options.fetch(options.url, {
|
|
130
|
+
body: options.body,
|
|
131
|
+
headers: {
|
|
132
|
+
Accept: "application/vnd.github+json",
|
|
133
|
+
Authorization: `Bearer ${options.token}`,
|
|
134
|
+
"X-GitHub-Api-Version": GITHUB_API_VERSION,
|
|
135
|
+
...(options.closeConnection ? { Connection: "close" } : {}),
|
|
136
|
+
...(options.body === undefined
|
|
137
|
+
? {}
|
|
138
|
+
: { "Content-Type": "application/json" }),
|
|
139
|
+
},
|
|
140
|
+
method: options.method,
|
|
141
|
+
signal: AbortSignal.timeout(options.timeoutMs),
|
|
142
|
+
});
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return { ok: false, reason: boundedTransportReason(error) };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!response.ok) {
|
|
148
|
+
if (!isTransientStatus(response.status)) {
|
|
149
|
+
throw errors.refusal(response.status, response.statusText);
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
reason: `GitHub API ${response.status} ${response.statusText}`,
|
|
154
|
+
status: response.status,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
return { ok: true, value: (await response.json()) as unknown };
|
|
160
|
+
} catch (error) {
|
|
161
|
+
// A 2xx whose body dies mid-read is the transport failing, not GitHub
|
|
162
|
+
// refusing: the EPIPE that motivated #830 lands exactly here.
|
|
163
|
+
return { ok: false, reason: boundedTransportReason(error) };
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** Run one GitHub JSON request with bounded transport retries. */
|
|
168
|
+
export const githubJson = async (
|
|
169
|
+
options: GithubJsonOptions,
|
|
170
|
+
errors: GithubJsonErrors
|
|
171
|
+
): Promise<unknown> => {
|
|
172
|
+
const attempts = Math.max(1, options.attempts ?? TRANSPORT_RETRY_ATTEMPTS);
|
|
173
|
+
let outcome = await githubJsonAttempt(options, errors);
|
|
174
|
+
|
|
175
|
+
for (let attempt = 2; attempt <= attempts && !outcome.ok; attempt += 1) {
|
|
176
|
+
// oxlint-disable-next-line no-await-in-loop -- bounded backoff between sequential retries
|
|
177
|
+
await transportWait(TRANSPORT_RETRY_BACKOFF_MS * 2 ** (attempt - 2));
|
|
178
|
+
// oxlint-disable-next-line no-await-in-loop -- retries are sequential by design
|
|
179
|
+
outcome = await githubJsonAttempt(options, errors);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (outcome.ok) {
|
|
183
|
+
return outcome.value;
|
|
184
|
+
}
|
|
185
|
+
throw errors.transport(outcome, attempts);
|
|
186
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-target withdrawal conditions for the candidate and production impact
|
|
3
|
+
* routing seams. Both seams emit the same condition text, so one
|
|
4
|
+
* implementation owns it.
|
|
5
|
+
*
|
|
6
|
+
* A cross-job condition and a same-job condition read different GitHub
|
|
7
|
+
* expression sources. `demandedIf` requires the decision job id and reads
|
|
8
|
+
* `needs.<job>`; `demandedIfAtStep` reads `steps.<stepId>` and takes no job
|
|
9
|
+
* id. The caller picks the seam by name, so an omitted job id can no longer
|
|
10
|
+
* emit a same-job condition where a cross-job condition was meant.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
interface ImpactDemandConditionOptions {
|
|
14
|
+
/** Output key that carries the decision verdict. */
|
|
15
|
+
readonly decisionOutput: string;
|
|
16
|
+
/** Seam name used in the unknown-target error. */
|
|
17
|
+
readonly label: string;
|
|
18
|
+
/** Id of the decision step inside the decision job. */
|
|
19
|
+
readonly stepId: string;
|
|
20
|
+
/** Target name to GitHub output key. */
|
|
21
|
+
readonly targetOutputs: Readonly<Record<string, string>>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ImpactDemandConditions {
|
|
25
|
+
/**
|
|
26
|
+
* Cross-job condition for a job that lists the decision job in `needs`.
|
|
27
|
+
* The decision job id is required.
|
|
28
|
+
*/
|
|
29
|
+
readonly demandedIf: (targetName: string, decisionJob: string) => string;
|
|
30
|
+
/** Same-job condition for a step that follows the decision step. */
|
|
31
|
+
readonly demandedIfAtStep: (targetName: string) => string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const impactDemandConditions = (
|
|
35
|
+
options: ImpactDemandConditionOptions
|
|
36
|
+
): ImpactDemandConditions => {
|
|
37
|
+
const targetOutput = (targetName: string): string => {
|
|
38
|
+
const output = options.targetOutputs[targetName];
|
|
39
|
+
if (output === undefined) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Unknown ${options.label} impact target "${targetName}".`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return output;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const condition = (
|
|
48
|
+
source: string,
|
|
49
|
+
outcomeKey: string,
|
|
50
|
+
output: string
|
|
51
|
+
): string =>
|
|
52
|
+
`${source}.${outcomeKey} != 'success' || ${source}.outputs.${options.decisionOutput} != 'usable' || ${source}.outputs.${output} != 'withdrawn'`;
|
|
53
|
+
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
demandedIf: (targetName: string, decisionJob: string) => {
|
|
56
|
+
const output = targetOutput(targetName);
|
|
57
|
+
if (decisionJob.trim().length === 0) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`A cross-job ${options.label} impact condition requires the decision job id.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return `always() && (${condition(`needs.${decisionJob}`, "result", output)})`;
|
|
63
|
+
},
|
|
64
|
+
demandedIfAtStep: (targetName: string) =>
|
|
65
|
+
condition(`steps.${options.stepId}`, "outcome", targetOutput(targetName)),
|
|
66
|
+
});
|
|
67
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -8,11 +8,22 @@
|
|
|
8
8
|
* loading or owning that profile (ADR 0021).
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
export {
|
|
12
|
+
ALCHEMY_BASELINE,
|
|
13
|
+
type AlchemyBaselinePackageJson,
|
|
14
|
+
assertAlchemyBaseline,
|
|
15
|
+
type AssertAlchemyBaselineInput,
|
|
16
|
+
} from "./alchemy-baseline.ts";
|
|
11
17
|
export {
|
|
12
18
|
NODE_PNPM_ACTION_FAMILY_NODE24,
|
|
13
19
|
type NodePnpmActionFamily,
|
|
14
20
|
type PinnedAction,
|
|
21
|
+
UPLOAD_ARTIFACT,
|
|
15
22
|
} from "./actions.ts";
|
|
23
|
+
export {
|
|
24
|
+
FACTORY_CANDIDATE_PULL_REQUEST_TYPES,
|
|
25
|
+
factoryCandidateOrPushCondition,
|
|
26
|
+
} from "./candidate-lifecycle.ts";
|
|
16
27
|
export {
|
|
17
28
|
bundleAlchemyEntry,
|
|
18
29
|
type BundleAlchemyEntryOptions,
|
|
@@ -26,6 +37,29 @@ export {
|
|
|
26
37
|
type ParseLocalPreviewStageExpected,
|
|
27
38
|
parseLocalPreviewStage,
|
|
28
39
|
} from "./disposable-stage.ts";
|
|
40
|
+
export {
|
|
41
|
+
previewProofLifecycle,
|
|
42
|
+
type PreviewProofCandidate,
|
|
43
|
+
type PreviewProofCleanupOutcome,
|
|
44
|
+
type PreviewProofCleanupStatus,
|
|
45
|
+
type PreviewProofEnvelopeEvidence,
|
|
46
|
+
type PreviewProofLifecycleEvent,
|
|
47
|
+
type PreviewProofLifecycleState,
|
|
48
|
+
type PreviewProofRegistration,
|
|
49
|
+
type PreviewProofResolveQuery,
|
|
50
|
+
} from "./preview-proof-lifecycle.ts";
|
|
51
|
+
export {
|
|
52
|
+
PREVIEW_PROOF_INVENTORY_CHECK_NAME,
|
|
53
|
+
PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS,
|
|
54
|
+
previewProofInventory,
|
|
55
|
+
type PreviewProofInventoryAccess,
|
|
56
|
+
type PreviewProofInventoryCleanupInput,
|
|
57
|
+
type PreviewProofInventoryListInput,
|
|
58
|
+
type PreviewProofInventoryPersistInput,
|
|
59
|
+
type PreviewProofInventoryStore,
|
|
60
|
+
type PreviewProofInventoryTransport,
|
|
61
|
+
PreviewProofTransportError,
|
|
62
|
+
} from "./preview-proof-inventory.ts";
|
|
29
63
|
export {
|
|
30
64
|
type CheckoutStepOptions,
|
|
31
65
|
type FactoryWorkflowArtifact,
|
|
@@ -33,17 +67,32 @@ export {
|
|
|
33
67
|
type FactoryWorkflowSetupOptions,
|
|
34
68
|
factoryWorkflow,
|
|
35
69
|
type InstallStepOptions,
|
|
70
|
+
SETUP_STEP_ROLES,
|
|
36
71
|
type SetupNodeStepOptions,
|
|
72
|
+
type SetupStepRole,
|
|
73
|
+
setupStepsForRoles,
|
|
37
74
|
type WorkflowStep,
|
|
38
75
|
} from "./factory-workflow.ts";
|
|
39
76
|
export {
|
|
77
|
+
FACTORY_CURSOR_OIDC_AUDIENCE,
|
|
78
|
+
FACTORY_CURSOR_OIDC_ISSUER,
|
|
79
|
+
FACTORY_CURSOR_OIDC_JWKS_URL,
|
|
80
|
+
FACTORY_CURSOR_OIDC_MANAGED_RUNTIME,
|
|
81
|
+
FACTORY_APP_BROKER_ORIGIN,
|
|
82
|
+
FACTORY_APP_BROKER_PATH,
|
|
83
|
+
} from "./cursor-oidc.ts";
|
|
84
|
+
export {
|
|
85
|
+
FACTORY_APP_BROKER_TOKEN_PERMISSIONS,
|
|
40
86
|
GitHubApiError,
|
|
87
|
+
GitHubAppTokenTransportError,
|
|
41
88
|
type GithubAppCredentials,
|
|
89
|
+
type GithubAppInstallationPermissions,
|
|
42
90
|
githubAppJwt,
|
|
43
91
|
type GithubAppTokenOptions,
|
|
44
92
|
mintInstallationToken,
|
|
45
93
|
} from "./github-app-token.ts";
|
|
46
94
|
export {
|
|
95
|
+
EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER,
|
|
47
96
|
type ExecuteAlchemyEntryOptions,
|
|
48
97
|
type ExecuteAlchemyEntryResult,
|
|
49
98
|
executeAlchemyEntry,
|
|
@@ -59,7 +108,9 @@ export {
|
|
|
59
108
|
FACTORY_PROOF_GATE_REASON_OUTPUT,
|
|
60
109
|
FACTORY_PROOF_GATE_REASONS,
|
|
61
110
|
FACTORY_PROOF_GATE_SHELL,
|
|
111
|
+
FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT,
|
|
62
112
|
FACTORY_PROOF_GATE_STEP_ID,
|
|
113
|
+
FACTORY_PROOF_GATE_STEP_NAME,
|
|
63
114
|
type FactoryProofGateOptions,
|
|
64
115
|
type FactoryProofGateReason,
|
|
65
116
|
factoryProofGateScript,
|
|
@@ -70,7 +121,130 @@ export {
|
|
|
70
121
|
type ProofReuseCoverageInput,
|
|
71
122
|
type ProofReuseCoverageReport,
|
|
72
123
|
proofReuseRequiredCommands,
|
|
124
|
+
resolveProofReuseCommands,
|
|
73
125
|
} from "./proof-reuse-gate.ts";
|
|
126
|
+
export {
|
|
127
|
+
type FactoryProofReusePresentationOptions,
|
|
128
|
+
type FactoryProofReuseSummaryStep,
|
|
129
|
+
type FactoryProofTimingStartStep,
|
|
130
|
+
factoryProofReuseSummaryStep,
|
|
131
|
+
factoryProofTimingStartStep,
|
|
132
|
+
} from "./proof-reuse-presentation.ts";
|
|
133
|
+
export {
|
|
134
|
+
FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT,
|
|
135
|
+
FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT,
|
|
136
|
+
FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT,
|
|
137
|
+
FACTORY_CANDIDATE_IMPACT_STEP_ID,
|
|
138
|
+
FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT,
|
|
139
|
+
type FactoryCandidateImpactWorkflow,
|
|
140
|
+
type FactoryCandidateImpactWorkflowOptions,
|
|
141
|
+
factoryCandidateImpactWorkflow,
|
|
142
|
+
} from "./candidate-impact-workflow.ts";
|
|
143
|
+
export {
|
|
144
|
+
FACTORY_LIFECYCLE_CONTRACT_JOB_ID,
|
|
145
|
+
FACTORY_LIFECYCLE_CONTRACT_JOB_NAME,
|
|
146
|
+
type FactoryLifecycleContractLane,
|
|
147
|
+
type FactoryLifecycleContractLaneOptions,
|
|
148
|
+
factoryLifecycleContractLane,
|
|
149
|
+
} from "./lifecycle-contract-lane.ts";
|
|
150
|
+
export {
|
|
151
|
+
FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID,
|
|
152
|
+
FACTORY_MERGE_FREEZE_CHECK_NAME,
|
|
153
|
+
FACTORY_MERGE_FREEZE_IF,
|
|
154
|
+
FACTORY_MERGE_FREEZE_JOB_ID,
|
|
155
|
+
FACTORY_MERGE_FREEZE_JOB_NAME,
|
|
156
|
+
FACTORY_MERGE_FREEZE_PERMISSIONS,
|
|
157
|
+
FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION,
|
|
158
|
+
FACTORY_MERGE_TARGET_REF_CONDITION,
|
|
159
|
+
type FactoryMergeFreezeJob,
|
|
160
|
+
factoryMergeFreezeJob,
|
|
161
|
+
type FactoryMergeFreezeJobOptions,
|
|
162
|
+
factoryMergeFreezeScript,
|
|
163
|
+
} from "./merge-freeze-job.ts";
|
|
164
|
+
export {
|
|
165
|
+
FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID,
|
|
166
|
+
FACTORY_PR_STATUS_HUD_CONCURRENCY,
|
|
167
|
+
FACTORY_PR_STATUS_HUD_IF,
|
|
168
|
+
FACTORY_PR_STATUS_HUD_JOB_ID,
|
|
169
|
+
FACTORY_PR_STATUS_HUD_JOB_NAME,
|
|
170
|
+
FACTORY_PR_STATUS_HUD_PERMISSIONS,
|
|
171
|
+
FACTORY_PR_STATUS_HUD_PLAN_PATH,
|
|
172
|
+
type FactoryPrStatusHudWorkflow,
|
|
173
|
+
type FactoryPrStatusHudWorkflowOptions,
|
|
174
|
+
factoryPrStatusHudWorkflow,
|
|
175
|
+
} from "./pr-status-hud-workflow.ts";
|
|
176
|
+
export {
|
|
177
|
+
FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID,
|
|
178
|
+
FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME,
|
|
179
|
+
type FactoryPreviewCleanupAuditJob,
|
|
180
|
+
type FactoryPreviewCleanupDestroyJob,
|
|
181
|
+
type FactoryPreviewCleanupTopology,
|
|
182
|
+
type FactoryPreviewCleanupTopologyOptions,
|
|
183
|
+
factoryPreviewCleanupTopology,
|
|
184
|
+
previewCleanupDestroyJobId,
|
|
185
|
+
} from "./preview-cleanup-topology.ts";
|
|
186
|
+
export {
|
|
187
|
+
type FactoryPreviewReceiptWorkflow,
|
|
188
|
+
type FactoryPreviewReceiptWorkflowOptions,
|
|
189
|
+
factoryPreviewReceiptWorkflow,
|
|
190
|
+
} from "./preview-receipt-workflow.ts";
|
|
191
|
+
export {
|
|
192
|
+
FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT,
|
|
193
|
+
FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT,
|
|
194
|
+
FACTORY_PRODUCTION_IMPACT_STEP_ID,
|
|
195
|
+
FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT,
|
|
196
|
+
type FactoryProductionImpactWorkflow,
|
|
197
|
+
type FactoryProductionImpactWorkflowOptions,
|
|
198
|
+
factoryProductionImpactWorkflow,
|
|
199
|
+
productionImpactTargetOutput,
|
|
200
|
+
} from "./production-impact-workflow.ts";
|
|
201
|
+
export {
|
|
202
|
+
FACTORY_PUSH_IDENTITY_SCHEMA_VERSION,
|
|
203
|
+
type FactoryPushIdentityConsumer,
|
|
204
|
+
type FactoryPushIdentityConsumerOptions,
|
|
205
|
+
type FactoryPushIdentityDisposition,
|
|
206
|
+
type FactoryPushIdentityEnvelope,
|
|
207
|
+
factoryPushIdentityConsumer,
|
|
208
|
+
type FactoryPushIdentityProducer,
|
|
209
|
+
type FactoryPushIdentityProducerOptions,
|
|
210
|
+
factoryPushIdentityProducer,
|
|
211
|
+
} from "./push-identity-workflow.ts";
|
|
212
|
+
export {
|
|
213
|
+
captureVitestProfileEnvironment,
|
|
214
|
+
normalizeVitestProfileSample,
|
|
215
|
+
runVitestProfile,
|
|
216
|
+
VITEST_PROFILE_SCHEMA_VERSION,
|
|
217
|
+
VITEST_PROFILE_TOOL,
|
|
218
|
+
type VitestJsonReport,
|
|
219
|
+
type VitestProfile,
|
|
220
|
+
type VitestProfileDependencies,
|
|
221
|
+
type VitestProfileDurationSummary,
|
|
222
|
+
type VitestProfileEnvironment,
|
|
223
|
+
VitestProfileError,
|
|
224
|
+
type VitestProfileOptions,
|
|
225
|
+
type VitestProfileSample,
|
|
226
|
+
type VitestProfileSampleExecution,
|
|
227
|
+
type VitestTestStatus,
|
|
228
|
+
writeVitestProfile,
|
|
229
|
+
} from "./vitest-profile.ts";
|
|
230
|
+
export {
|
|
231
|
+
readVitestProfileDocument,
|
|
232
|
+
type VitestProfileReadResult,
|
|
233
|
+
} from "./vitest-profile-reader.ts";
|
|
234
|
+
export {
|
|
235
|
+
assertVerifyRunnerPolicy,
|
|
236
|
+
factoryVerifyRunner,
|
|
237
|
+
type FactoryRunnerDecision,
|
|
238
|
+
type FactoryRunnerHome,
|
|
239
|
+
type FactoryRunnerKind,
|
|
240
|
+
type FactoryRunnerOverride,
|
|
241
|
+
type FactoryVerifyRunner,
|
|
242
|
+
type FactoryVerifyRunnerMismatch,
|
|
243
|
+
type FactoryVerifyRunnerPolicyInput,
|
|
244
|
+
type FactoryVerifyRunnerPolicyReport,
|
|
245
|
+
type FactoryVerifyRunnerTable,
|
|
246
|
+
verifyRunnerPolicy,
|
|
247
|
+
} from "./verify-runner-policy.ts";
|
|
74
248
|
export {
|
|
75
249
|
assertWorkflowShellParses,
|
|
76
250
|
workflowRunBlocks,
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { WorkflowStep } from "./factory-workflow.ts";
|
|
2
|
+
|
|
3
|
+
export const FACTORY_LIFECYCLE_CONTRACT_JOB_ID = "factory-contracts";
|
|
4
|
+
export const FACTORY_LIFECYCLE_CONTRACT_JOB_NAME =
|
|
5
|
+
"Factory / Alchemy Contracts";
|
|
6
|
+
|
|
7
|
+
const JOB_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*$/u;
|
|
8
|
+
const PACKAGE_NAME = "(?:@[A-Za-z0-9._~-]+\\/)?[A-Za-z0-9._~-]+";
|
|
9
|
+
const COLON_SCRIPT = "[A-Za-z][\\w.-]*:[\\w:.-]+";
|
|
10
|
+
const RUN_SCRIPT = "[A-Za-z][\\w:.-]*";
|
|
11
|
+
const PNPM = `pnpm(?: --filter(?:=| )${PACKAGE_NAME})?`;
|
|
12
|
+
const OTHER_MANAGER = "(?:bun|npm|yarn)";
|
|
13
|
+
const ALLOWED_PACKAGE_SCRIPT = new RegExp(
|
|
14
|
+
`^(?:${PNPM} run ${RUN_SCRIPT}|${PNPM} ${COLON_SCRIPT}|${OTHER_MANAGER} run ${RUN_SCRIPT}|${OTHER_MANAGER} ${COLON_SCRIPT})$`,
|
|
15
|
+
"u"
|
|
16
|
+
);
|
|
17
|
+
const CREDENTIAL_ENV = /ALCHEMY_PASSWORD|CLOUDFLARE_|CF_API_|secrets\./u;
|
|
18
|
+
const SHELL_OPERATOR = /&&|\|\||;|\||`|\$\(|\$\{|\$[A-Za-z_*@#?!$0-9-]/u;
|
|
19
|
+
|
|
20
|
+
const EVIDENCE_SUMMARY = `{
|
|
21
|
+
echo "## Factory contract evidence"
|
|
22
|
+
echo
|
|
23
|
+
echo "- Status: $JOB_STATUS"
|
|
24
|
+
echo "- Covers the consumer's declared Alchemy/product-stack lifecycle contracts."
|
|
25
|
+
echo "- This static lane is non-credentialed and does not prove live deploy, D1, smoke, convergence, or cleanup."
|
|
26
|
+
} >> "$GITHUB_STEP_SUMMARY"`;
|
|
27
|
+
|
|
28
|
+
export interface FactoryLifecycleContractLaneOptions {
|
|
29
|
+
readonly command: string;
|
|
30
|
+
readonly jobId?: string;
|
|
31
|
+
readonly jobName?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface FactoryLifecycleContractLane {
|
|
35
|
+
readonly jobId: string;
|
|
36
|
+
readonly jobName: string;
|
|
37
|
+
readonly steps: readonly WorkflowStep[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const assertSingleLine = (name: string, value: string): void => {
|
|
41
|
+
if (value.trim() !== value || value.length === 0 || /[\r\n]/u.test(value)) {
|
|
42
|
+
throw new Error(`${name} must be a single non-empty line.`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const assertPackageScriptCommand = (command: string): void => {
|
|
47
|
+
assertSingleLine("lifecycleContract.command", command);
|
|
48
|
+
if (CREDENTIAL_ENV.test(command)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"lifecycleContract.command must not interpolate GitHub secrets or credential environment names."
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (SHELL_OPERATOR.test(command)) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"lifecycleContract.command must not include a shell operator or environment expansion."
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (!ALLOWED_PACKAGE_SCRIPT.test(command)) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
"lifecycleContract.command must be a package script invocation (`run <script>` or a colon-namespaced shorthand), never a package-manager builtin or a direct Vitest run."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generate the factory-owned non-credentialed lifecycle-contract lane
|
|
67
|
+
* (#765). Consumers declare the package-script command in
|
|
68
|
+
* `software-factory.profile.json`; this helper never loads that profile.
|
|
69
|
+
* Callers pass the parsed declaration (or omit it) and include or skip the
|
|
70
|
+
* returned job. Setup, runners, topology, and credentials stay with the
|
|
71
|
+
* caller — and this lane must never receive credentials.
|
|
72
|
+
*
|
|
73
|
+
* The generated steps run only the declared package script and write an
|
|
74
|
+
* always() evidence summary of what the lane proves and does not prove.
|
|
75
|
+
* The command must be a package-script invocation: `run <script>`, or a
|
|
76
|
+
* shorthand whose script name contains `:` (`pnpm test:factory`). Optional
|
|
77
|
+
* pnpm `--filter <pkg>` may precede either form. Shell operators, credential
|
|
78
|
+
* env, extra flags, and direct Vitest are refused.
|
|
79
|
+
*/
|
|
80
|
+
export const factoryLifecycleContractLane = (
|
|
81
|
+
declaration?: FactoryLifecycleContractLaneOptions
|
|
82
|
+
): FactoryLifecycleContractLane | undefined => {
|
|
83
|
+
if (declaration === undefined) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
assertPackageScriptCommand(declaration.command);
|
|
88
|
+
const jobId = declaration.jobId ?? FACTORY_LIFECYCLE_CONTRACT_JOB_ID;
|
|
89
|
+
const jobName = declaration.jobName ?? FACTORY_LIFECYCLE_CONTRACT_JOB_NAME;
|
|
90
|
+
if (!JOB_ID_PATTERN.test(jobId)) {
|
|
91
|
+
throw new Error("lifecycleContract.jobId must be a GitHub Actions job id.");
|
|
92
|
+
}
|
|
93
|
+
assertSingleLine("lifecycleContract.jobName", jobName);
|
|
94
|
+
|
|
95
|
+
const runStep: WorkflowStep = Object.freeze({
|
|
96
|
+
name: "Run lifecycle contracts",
|
|
97
|
+
run: declaration.command,
|
|
98
|
+
});
|
|
99
|
+
const summaryStep: WorkflowStep = Object.freeze({
|
|
100
|
+
env: Object.freeze({
|
|
101
|
+
JOB_STATUS: `\${{ job.status }}`,
|
|
102
|
+
}),
|
|
103
|
+
if: "always()",
|
|
104
|
+
name: "Summarize factory-contract evidence",
|
|
105
|
+
run: EVIDENCE_SUMMARY,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
jobId,
|
|
110
|
+
jobName,
|
|
111
|
+
steps: Object.freeze([runStep, summaryStep]),
|
|
112
|
+
});
|
|
113
|
+
};
|