flakelab 0.1.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 +341 -0
- package/bin/flakelab.mjs +3 -0
- package/dist/artifacts/ndjson.d.ts +3 -0
- package/dist/artifacts/ndjson.js +16 -0
- package/dist/artifacts/ndjson.js.map +1 -0
- package/dist/bisect/archive.d.ts +1 -0
- package/dist/bisect/archive.js +14 -0
- package/dist/bisect/archive.js.map +1 -0
- package/dist/bisect/confidence.d.ts +7 -0
- package/dist/bisect/confidence.js +27 -0
- package/dist/bisect/confidence.js.map +1 -0
- package/dist/bisect/engine.d.ts +10 -0
- package/dist/bisect/engine.js +110 -0
- package/dist/bisect/engine.js.map +1 -0
- package/dist/bisect/git.d.ts +7 -0
- package/dist/bisect/git.js +56 -0
- package/dist/bisect/git.js.map +1 -0
- package/dist/bisect/schema.d.ts +82 -0
- package/dist/bisect/schema.js +33 -0
- package/dist/bisect/schema.js.map +1 -0
- package/dist/bisect/solari-command.d.ts +7 -0
- package/dist/bisect/solari-command.js +95 -0
- package/dist/bisect/solari-command.js.map +1 -0
- package/dist/bisect/solari-evaluator.d.ts +20 -0
- package/dist/bisect/solari-evaluator.js +310 -0
- package/dist/bisect/solari-evaluator.js.map +1 -0
- package/dist/ci/changed-tests.d.ts +7 -0
- package/dist/ci/changed-tests.js +104 -0
- package/dist/ci/changed-tests.js.map +1 -0
- package/dist/ci/job-summary.d.ts +11 -0
- package/dist/ci/job-summary.js +45 -0
- package/dist/ci/job-summary.js.map +1 -0
- package/dist/ci/select-command.d.ts +1 -0
- package/dist/ci/select-command.js +49 -0
- package/dist/ci/select-command.js.map +1 -0
- package/dist/ci/summary-command.d.ts +1 -0
- package/dist/ci/summary-command.js +46 -0
- package/dist/ci/summary-command.js.map +1 -0
- package/dist/cli-help.d.ts +2 -0
- package/dist/cli-help.js +47 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +121 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/bisect.d.ts +2 -0
- package/dist/commands/bisect.js +63 -0
- package/dist/commands/bisect.js.map +1 -0
- package/dist/commands/diagnose.d.ts +2 -0
- package/dist/commands/diagnose.js +27 -0
- package/dist/commands/diagnose.js.map +1 -0
- package/dist/commands/discover.d.ts +2 -0
- package/dist/commands/discover.js +46 -0
- package/dist/commands/discover.js.map +1 -0
- package/dist/commands/doctor.d.ts +8 -0
- package/dist/commands/doctor.js +78 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/investigate.d.ts +2 -0
- package/dist/commands/investigate.js +43 -0
- package/dist/commands/investigate.js.map +1 -0
- package/dist/commands/options.d.ts +38 -0
- package/dist/commands/options.js +35 -0
- package/dist/commands/options.js.map +1 -0
- package/dist/commands/prove.d.ts +2 -0
- package/dist/commands/prove.js +21 -0
- package/dist/commands/prove.js.map +1 -0
- package/dist/commands/repair.d.ts +2 -0
- package/dist/commands/repair.js +55 -0
- package/dist/commands/repair.js.map +1 -0
- package/dist/commands/replay.d.ts +2 -0
- package/dist/commands/replay.js +26 -0
- package/dist/commands/replay.js.map +1 -0
- package/dist/commands/report.d.ts +2 -0
- package/dist/commands/report.js +79 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/scan.d.ts +12 -0
- package/dist/commands/scan.js +86 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/core/plan.d.ts +3 -0
- package/dist/core/plan.js +17 -0
- package/dist/core/plan.js.map +1 -0
- package/dist/discovery/evaluate.d.ts +22 -0
- package/dist/discovery/evaluate.js +81 -0
- package/dist/discovery/evaluate.js.map +1 -0
- package/dist/discovery/minimize.d.ts +24 -0
- package/dist/discovery/minimize.js +73 -0
- package/dist/discovery/minimize.js.map +1 -0
- package/dist/domain/schema.d.ts +155 -0
- package/dist/domain/schema.js +67 -0
- package/dist/domain/schema.js.map +1 -0
- package/dist/faults/install.d.ts +4 -0
- package/dist/faults/install.js +9 -0
- package/dist/faults/install.js.map +1 -0
- package/dist/faults/network-delay.d.ts +5 -0
- package/dist/faults/network-delay.js +34 -0
- package/dist/faults/network-delay.js.map +1 -0
- package/dist/faults/request-failure.d.ts +5 -0
- package/dist/faults/request-failure.js +24 -0
- package/dist/faults/request-failure.js.map +1 -0
- package/dist/investigator/agent.d.ts +26 -0
- package/dist/investigator/agent.js +197 -0
- package/dist/investigator/agent.js.map +1 -0
- package/dist/investigator/budget.d.ts +14 -0
- package/dist/investigator/budget.js +39 -0
- package/dist/investigator/budget.js.map +1 -0
- package/dist/investigator/file.d.ts +2 -0
- package/dist/investigator/file.js +7 -0
- package/dist/investigator/file.js.map +1 -0
- package/dist/investigator/groq.d.ts +5 -0
- package/dist/investigator/groq.js +26 -0
- package/dist/investigator/groq.js.map +1 -0
- package/dist/investigator/ledger.d.ts +17 -0
- package/dist/investigator/ledger.js +121 -0
- package/dist/investigator/ledger.js.map +1 -0
- package/dist/investigator/safe-source.d.ts +6 -0
- package/dist/investigator/safe-source.js +79 -0
- package/dist/investigator/safe-source.js.map +1 -0
- package/dist/investigator/schema.d.ts +110 -0
- package/dist/investigator/schema.js +53 -0
- package/dist/investigator/schema.js.map +1 -0
- package/dist/playwright.d.ts +3 -0
- package/dist/playwright.js +21 -0
- package/dist/playwright.js.map +1 -0
- package/dist/providers/errors.d.ts +21 -0
- package/dist/providers/errors.js +159 -0
- package/dist/providers/errors.js.map +1 -0
- package/dist/repair/file.d.ts +2 -0
- package/dist/repair/file.js +6 -0
- package/dist/repair/file.js.map +1 -0
- package/dist/repair/generator.d.ts +12 -0
- package/dist/repair/generator.js +74 -0
- package/dist/repair/generator.js.map +1 -0
- package/dist/repair/policy.d.ts +2 -0
- package/dist/repair/policy.js +70 -0
- package/dist/repair/policy.js.map +1 -0
- package/dist/repair/remote-proof-runner.d.ts +1 -0
- package/dist/repair/remote-proof-runner.js +53 -0
- package/dist/repair/remote-proof-runner.js.map +1 -0
- package/dist/repair/schema.d.ts +78 -0
- package/dist/repair/schema.js +44 -0
- package/dist/repair/schema.js.map +1 -0
- package/dist/repair/solari-validator.d.ts +25 -0
- package/dist/repair/solari-validator.js +231 -0
- package/dist/repair/solari-validator.js.map +1 -0
- package/dist/repair/validator.d.ts +16 -0
- package/dist/repair/validator.js +81 -0
- package/dist/repair/validator.js.map +1 -0
- package/dist/repair/workspace.d.ts +7 -0
- package/dist/repair/workspace.js +40 -0
- package/dist/repair/workspace.js.map +1 -0
- package/dist/report/browser-entry.d.ts +2 -0
- package/dist/report/browser-entry.js +15 -0
- package/dist/report/browser-entry.js.map +1 -0
- package/dist/report/bundle.d.ts +2 -0
- package/dist/report/bundle.js +77 -0
- package/dist/report/bundle.js.map +1 -0
- package/dist/report/classification.d.ts +9 -0
- package/dist/report/classification.js +55 -0
- package/dist/report/classification.js.map +1 -0
- package/dist/report/components/artifacts.d.ts +4 -0
- package/dist/report/components/artifacts.js +6 -0
- package/dist/report/components/artifacts.js.map +1 -0
- package/dist/report/components/experiments.d.ts +4 -0
- package/dist/report/components/experiments.js +7 -0
- package/dist/report/components/experiments.js.map +1 -0
- package/dist/report/components/hypotheses.d.ts +4 -0
- package/dist/report/components/hypotheses.js +26 -0
- package/dist/report/components/hypotheses.js.map +1 -0
- package/dist/report/components/indicators.d.ts +32 -0
- package/dist/report/components/indicators.js +42 -0
- package/dist/report/components/indicators.js.map +1 -0
- package/dist/report/components/layout.d.ts +29 -0
- package/dist/report/components/layout.js +20 -0
- package/dist/report/components/layout.js.map +1 -0
- package/dist/report/components/proof.d.ts +4 -0
- package/dist/report/components/proof.js +34 -0
- package/dist/report/components/proof.js.map +1 -0
- package/dist/report/components/reproduction.d.ts +4 -0
- package/dist/report/components/reproduction.js +19 -0
- package/dist/report/components/reproduction.js.map +1 -0
- package/dist/report/components/summary.d.ts +4 -0
- package/dist/report/components/summary.js +12 -0
- package/dist/report/components/summary.js.map +1 -0
- package/dist/report/components/verdict.d.ts +4 -0
- package/dist/report/components/verdict.js +27 -0
- package/dist/report/components/verdict.js.map +1 -0
- package/dist/report/model.d.ts +19 -0
- package/dist/report/model.js +82 -0
- package/dist/report/model.js.map +1 -0
- package/dist/report/open.d.ts +1 -0
- package/dist/report/open.js +24 -0
- package/dist/report/open.js.map +1 -0
- package/dist/report/publish.d.ts +12 -0
- package/dist/report/publish.js +67 -0
- package/dist/report/publish.js.map +1 -0
- package/dist/report/redaction.d.ts +1 -0
- package/dist/report/redaction.js +58 -0
- package/dist/report/redaction.js.map +1 -0
- package/dist/report/report-app.d.ts +6 -0
- package/dist/report/report-app.js +16 -0
- package/dist/report/report-app.js.map +1 -0
- package/dist/report/report-details.css +182 -0
- package/dist/report/report.css +404 -0
- package/dist/report/schema.d.ts +101 -0
- package/dist/report/schema.js +71 -0
- package/dist/report/schema.js.map +1 -0
- package/dist/reproducer/file.d.ts +3 -0
- package/dist/reproducer/file.js +14 -0
- package/dist/reproducer/file.js.map +1 -0
- package/dist/reproducer/schema.d.ts +17 -0
- package/dist/reproducer/schema.js +14 -0
- package/dist/reproducer/schema.js.map +1 -0
- package/dist/runner/local.d.ts +12 -0
- package/dist/runner/local.js +72 -0
- package/dist/runner/local.js.map +1 -0
- package/dist/runner/playwright-executor.d.ts +10 -0
- package/dist/runner/playwright-executor.js +148 -0
- package/dist/runner/playwright-executor.js.map +1 -0
- package/dist/security/credentials.d.ts +23 -0
- package/dist/security/credentials.js +105 -0
- package/dist/security/credentials.js.map +1 -0
- package/dist/solari/checkout-fixture.d.ts +3 -0
- package/dist/solari/checkout-fixture.js +54 -0
- package/dist/solari/checkout-fixture.js.map +1 -0
- package/dist/solari/executor.d.ts +17 -0
- package/dist/solari/executor.js +280 -0
- package/dist/solari/executor.js.map +1 -0
- package/dist/solari/retry.d.ts +7 -0
- package/dist/solari/retry.js +50 -0
- package/dist/solari/retry.js.map +1 -0
- package/dist/solari/run-demo.d.ts +21 -0
- package/dist/solari/run-demo.js +64 -0
- package/dist/solari/run-demo.js.map +1 -0
- package/dist/solari/transport.d.ts +1 -0
- package/dist/solari/transport.js +21 -0
- package/dist/solari/transport.js.map +1 -0
- package/dist/solari/usage.d.ts +23 -0
- package/dist/solari/usage.js +53 -0
- package/dist/solari/usage.js.map +1 -0
- package/dist/solari/websocket-proxy.d.ts +7 -0
- package/dist/solari/websocket-proxy.js +131 -0
- package/dist/solari/websocket-proxy.js.map +1 -0
- package/dist/ui/progress.d.ts +5 -0
- package/dist/ui/progress.js +16 -0
- package/dist/ui/progress.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const experimentResultSchema: z.ZodObject<{
|
|
3
|
+
confirmed: z.ZodBoolean;
|
|
4
|
+
dominantFailureSignature: z.ZodOptional<z.ZodString>;
|
|
5
|
+
dominantFailureReason: z.ZodOptional<z.ZodString>;
|
|
6
|
+
errors: z.ZodNumber;
|
|
7
|
+
failed: z.ZodNumber;
|
|
8
|
+
failureRate: z.ZodNumber;
|
|
9
|
+
lowerBound80: z.ZodNumber;
|
|
10
|
+
passed: z.ZodNumber;
|
|
11
|
+
trials: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare const experimentConditionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
14
|
+
kind: z.ZodLiteral<"baseline">;
|
|
15
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
16
|
+
kind: z.ZodLiteral<"network-delay">;
|
|
17
|
+
delayMs: z.ZodNumber;
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
19
|
+
kind: z.ZodLiteral<"request-failure">;
|
|
20
|
+
statusCode: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>], "kind">;
|
|
22
|
+
export declare const hypothesisSchema: z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
statement: z.ZodString;
|
|
25
|
+
prediction: z.ZodString;
|
|
26
|
+
status: z.ZodEnum<{
|
|
27
|
+
rejected: "rejected";
|
|
28
|
+
confirmed: "confirmed";
|
|
29
|
+
proposed: "proposed";
|
|
30
|
+
}>;
|
|
31
|
+
evidenceExperimentIds: z.ZodArray<z.ZodString>;
|
|
32
|
+
explanation: z.ZodString;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export declare const experimentEvidenceSchema: z.ZodObject<{
|
|
35
|
+
id: z.ZodString;
|
|
36
|
+
hypothesisId: z.ZodString;
|
|
37
|
+
condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
38
|
+
kind: z.ZodLiteral<"baseline">;
|
|
39
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
40
|
+
kind: z.ZodLiteral<"network-delay">;
|
|
41
|
+
delayMs: z.ZodNumber;
|
|
42
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
43
|
+
kind: z.ZodLiteral<"request-failure">;
|
|
44
|
+
statusCode: z.ZodNumber;
|
|
45
|
+
}, z.core.$strip>], "kind">;
|
|
46
|
+
result: z.ZodObject<{
|
|
47
|
+
confirmed: z.ZodBoolean;
|
|
48
|
+
dominantFailureSignature: z.ZodOptional<z.ZodString>;
|
|
49
|
+
dominantFailureReason: z.ZodOptional<z.ZodString>;
|
|
50
|
+
errors: z.ZodNumber;
|
|
51
|
+
failed: z.ZodNumber;
|
|
52
|
+
failureRate: z.ZodNumber;
|
|
53
|
+
lowerBound80: z.ZodNumber;
|
|
54
|
+
passed: z.ZodNumber;
|
|
55
|
+
trials: z.ZodNumber;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
export declare const investigationReportSchema: z.ZodObject<{
|
|
59
|
+
version: z.ZodLiteral<1>;
|
|
60
|
+
test: z.ZodString;
|
|
61
|
+
model: z.ZodString;
|
|
62
|
+
conclusion: z.ZodString;
|
|
63
|
+
conclusionHypothesisId: z.ZodString;
|
|
64
|
+
conclusionEvidenceIds: z.ZodArray<z.ZodString>;
|
|
65
|
+
hypotheses: z.ZodArray<z.ZodObject<{
|
|
66
|
+
id: z.ZodString;
|
|
67
|
+
statement: z.ZodString;
|
|
68
|
+
prediction: z.ZodString;
|
|
69
|
+
status: z.ZodEnum<{
|
|
70
|
+
rejected: "rejected";
|
|
71
|
+
confirmed: "confirmed";
|
|
72
|
+
proposed: "proposed";
|
|
73
|
+
}>;
|
|
74
|
+
evidenceExperimentIds: z.ZodArray<z.ZodString>;
|
|
75
|
+
explanation: z.ZodString;
|
|
76
|
+
}, z.core.$strip>>;
|
|
77
|
+
experiments: z.ZodArray<z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
hypothesisId: z.ZodString;
|
|
80
|
+
condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
81
|
+
kind: z.ZodLiteral<"baseline">;
|
|
82
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
83
|
+
kind: z.ZodLiteral<"network-delay">;
|
|
84
|
+
delayMs: z.ZodNumber;
|
|
85
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
86
|
+
kind: z.ZodLiteral<"request-failure">;
|
|
87
|
+
statusCode: z.ZodNumber;
|
|
88
|
+
}, z.core.$strip>], "kind">;
|
|
89
|
+
result: z.ZodObject<{
|
|
90
|
+
confirmed: z.ZodBoolean;
|
|
91
|
+
dominantFailureSignature: z.ZodOptional<z.ZodString>;
|
|
92
|
+
dominantFailureReason: z.ZodOptional<z.ZodString>;
|
|
93
|
+
errors: z.ZodNumber;
|
|
94
|
+
failed: z.ZodNumber;
|
|
95
|
+
failureRate: z.ZodNumber;
|
|
96
|
+
lowerBound80: z.ZodNumber;
|
|
97
|
+
passed: z.ZodNumber;
|
|
98
|
+
trials: z.ZodNumber;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
}, z.core.$strip>>;
|
|
101
|
+
usage: z.ZodObject<{
|
|
102
|
+
inputTokens: z.ZodNumber;
|
|
103
|
+
outputTokens: z.ZodNumber;
|
|
104
|
+
estimatedCostUsd: z.ZodNumber;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
export type ExperimentCondition = z.infer<typeof experimentConditionSchema>;
|
|
108
|
+
export type ExperimentEvidence = z.infer<typeof experimentEvidenceSchema>;
|
|
109
|
+
export type Hypothesis = z.infer<typeof hypothesisSchema>;
|
|
110
|
+
export type InvestigationReport = z.infer<typeof investigationReportSchema>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const experimentResultSchema = z.object({
|
|
3
|
+
confirmed: z.boolean(),
|
|
4
|
+
dominantFailureSignature: z.string().min(1).optional(),
|
|
5
|
+
dominantFailureReason: z.string().min(1).max(2_000).optional(),
|
|
6
|
+
errors: z.number().int().nonnegative(),
|
|
7
|
+
failed: z.number().int().nonnegative(),
|
|
8
|
+
failureRate: z.number().min(0).max(1),
|
|
9
|
+
lowerBound80: z.number().min(0).max(1),
|
|
10
|
+
passed: z.number().int().nonnegative(),
|
|
11
|
+
trials: z.number().int().nonnegative(),
|
|
12
|
+
});
|
|
13
|
+
export const experimentConditionSchema = z.discriminatedUnion("kind", [
|
|
14
|
+
z.object({ kind: z.literal("baseline") }),
|
|
15
|
+
z.object({
|
|
16
|
+
kind: z.literal("network-delay"),
|
|
17
|
+
delayMs: z.number().int().min(1).max(30_000),
|
|
18
|
+
}),
|
|
19
|
+
z.object({
|
|
20
|
+
kind: z.literal("request-failure"),
|
|
21
|
+
statusCode: z.number().int().min(400).max(599),
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
export const hypothesisSchema = z.object({
|
|
25
|
+
id: z.string().regex(/^H\d+$/u),
|
|
26
|
+
statement: z.string().min(8).max(500),
|
|
27
|
+
prediction: z.string().min(8).max(500),
|
|
28
|
+
status: z.enum(["proposed", "rejected", "confirmed"]),
|
|
29
|
+
evidenceExperimentIds: z.array(z.string().regex(/^E\d+$/u)),
|
|
30
|
+
explanation: z.string().max(1_000),
|
|
31
|
+
});
|
|
32
|
+
export const experimentEvidenceSchema = z.object({
|
|
33
|
+
id: z.string().regex(/^E\d+$/u),
|
|
34
|
+
hypothesisId: z.string().regex(/^H\d+$/u),
|
|
35
|
+
condition: experimentConditionSchema,
|
|
36
|
+
result: experimentResultSchema,
|
|
37
|
+
});
|
|
38
|
+
export const investigationReportSchema = z.object({
|
|
39
|
+
version: z.literal(1),
|
|
40
|
+
test: z.string().min(1),
|
|
41
|
+
model: z.string().min(1),
|
|
42
|
+
conclusion: z.string().min(8).max(2_000),
|
|
43
|
+
conclusionHypothesisId: z.string().regex(/^H\d+$/u),
|
|
44
|
+
conclusionEvidenceIds: z.array(z.string().regex(/^E\d+$/u)).min(1),
|
|
45
|
+
hypotheses: z.array(hypothesisSchema).min(2),
|
|
46
|
+
experiments: z.array(experimentEvidenceSchema).min(1),
|
|
47
|
+
usage: z.object({
|
|
48
|
+
inputTokens: z.number().int().nonnegative(),
|
|
49
|
+
outputTokens: z.number().int().nonnegative(),
|
|
50
|
+
estimatedCostUsd: z.number().nonnegative(),
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/investigator/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;IACtB,wBAAwB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtD,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IAC9D,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IACtC,MAAM,EAA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AAC,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;QAC3C,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;QAC5C,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE;KAC3C,CAAC;CACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { expect } from "@playwright/test";
|
|
2
|
+
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
3
|
+
export { expect };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { expect, test as base } from "@playwright/test";
|
|
2
|
+
import { installFault } from "./faults/install.js";
|
|
3
|
+
import { readNetworkDelayFromEnvironment } from "./faults/network-delay.js";
|
|
4
|
+
import { readRequestFailureFromEnvironment } from "./faults/request-failure.js";
|
|
5
|
+
function readFaultFromEnvironment() {
|
|
6
|
+
return readNetworkDelayFromEnvironment() ?? readRequestFailureFromEnvironment();
|
|
7
|
+
}
|
|
8
|
+
export const test = base.extend({
|
|
9
|
+
page: async ({ page }, use) => {
|
|
10
|
+
const fault = readFaultFromEnvironment();
|
|
11
|
+
const removeFault = fault ? await installFault(page, fault) : undefined;
|
|
12
|
+
try {
|
|
13
|
+
await use(page);
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
await removeFault?.();
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
export { expect };
|
|
21
|
+
//# sourceMappingURL=playwright.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.js","sourceRoot":"","sources":["../src/playwright.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAE/E,SAAS,wBAAwB;IAC/B,OAAO,+BAA+B,EAAE,IAAI,iCAAiC,EAAE,CAAA;AACjF,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,wBAAwB,EAAE,CAAA;QACxC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACvE,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,IAAI,CAAC,CAAA;QACjB,CAAC;gBAAS,CAAC;YACT,MAAM,WAAW,EAAE,EAAE,CAAA;QACvB,CAAC;IACH,CAAC;CACF,CAAC,CAAA;AAEF,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type ProviderName = "Groq" | "Solari";
|
|
2
|
+
export type ProviderFailureCategory = "authentication" | "billing" | "capacity" | "concurrency" | "configuration" | "network" | "permission" | "rate-limit" | "request" | "timeout" | "unavailable";
|
|
3
|
+
interface ProviderFailureOptions {
|
|
4
|
+
action: string;
|
|
5
|
+
category: ProviderFailureCategory;
|
|
6
|
+
provider: ProviderName;
|
|
7
|
+
retryable: boolean;
|
|
8
|
+
status?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class ProviderFailure extends Error {
|
|
11
|
+
readonly action: string;
|
|
12
|
+
readonly category: ProviderFailureCategory;
|
|
13
|
+
readonly provider: ProviderName;
|
|
14
|
+
readonly retryable: boolean;
|
|
15
|
+
readonly status?: number;
|
|
16
|
+
constructor(message: string, options: ProviderFailureOptions);
|
|
17
|
+
}
|
|
18
|
+
export declare function solariResponseFailure(response: Response): Promise<ProviderFailure>;
|
|
19
|
+
export declare function normalizeProviderError(error: Error): Error;
|
|
20
|
+
export declare function cliErrorMessage(error: Error): string;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { SolariError as BrowserSolariError } from "@solarisdk/browser";
|
|
2
|
+
import { ConnectionError, GatewayError, TimeoutError, } from "@solarisdk/sandbox";
|
|
3
|
+
import { APICallError, RetryError } from "ai";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const groqErrorSchema = z.object({
|
|
6
|
+
error: z.object({
|
|
7
|
+
code: z.string().optional(),
|
|
8
|
+
type: z.string().optional(),
|
|
9
|
+
}),
|
|
10
|
+
});
|
|
11
|
+
const solariErrorSchema = z.object({
|
|
12
|
+
code: z.string().optional(),
|
|
13
|
+
});
|
|
14
|
+
export class ProviderFailure extends Error {
|
|
15
|
+
action;
|
|
16
|
+
category;
|
|
17
|
+
provider;
|
|
18
|
+
retryable;
|
|
19
|
+
status;
|
|
20
|
+
constructor(message, options) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "ProviderFailure";
|
|
23
|
+
this.action = options.action;
|
|
24
|
+
this.category = options.category;
|
|
25
|
+
this.provider = options.provider;
|
|
26
|
+
this.retryable = options.retryable;
|
|
27
|
+
this.status = options.status;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function failure(provider, category, message, action, status, retryable = false) {
|
|
31
|
+
return new ProviderFailure(message, { action, category, provider, retryable, status });
|
|
32
|
+
}
|
|
33
|
+
function parseGroqCode(error) {
|
|
34
|
+
if (!error.responseBody) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const parsed = groqErrorSchema.safeParse(JSON.parse(error.responseBody));
|
|
39
|
+
return parsed.success ? parsed.data.error.code : undefined;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const GROQ_STATUS_FAILURES = new Map([
|
|
46
|
+
[401, () => failure("Groq", "authentication", "Groq rejected the configured API key.", "Replace GROQ_API_KEY or rerun with --prompt-credentials.", 401)],
|
|
47
|
+
[403, () => failure("Groq", "permission", "Groq denied access to the requested model.", "Enable the model for the Groq project or choose an allowed model.", 403)],
|
|
48
|
+
[404, () => failure("Groq", "configuration", "The configured Groq model is unavailable.", "Check --model and the models enabled for the Groq project.", 404)],
|
|
49
|
+
[408, () => failure("Groq", "timeout", "The Groq request timed out.", "Rerun the investigation; increase --max-seconds only if necessary.", 408, true)],
|
|
50
|
+
[413, () => failure("Groq", "request", "The Groq request exceeded the provider payload limit.", "Reduce the selected source context before rerunning.", 413)],
|
|
51
|
+
[429, () => failure("Groq", "rate-limit", "The Groq project reached a request or token limit.", "Wait for the limit to reset or raise the project limit, then rerun.", 429, true)],
|
|
52
|
+
[498, () => failure("Groq", "capacity", "Groq Flex capacity is temporarily unavailable.", "Retry later or use the default service tier.", 498, true)],
|
|
53
|
+
[499, () => failure("Groq", "timeout", "The Groq request was cancelled.", "Rerun the investigation when ready.", 499, true)],
|
|
54
|
+
]);
|
|
55
|
+
function groqCodeFailure(code, status) {
|
|
56
|
+
if (code === "invalid_api_key") {
|
|
57
|
+
return GROQ_STATUS_FAILURES.get(401)?.() ?? failure("Groq", "authentication", "Groq rejected the configured API key.", "Replace GROQ_API_KEY or rerun with --prompt-credentials.", status);
|
|
58
|
+
}
|
|
59
|
+
if (code === "capacity_exceeded") {
|
|
60
|
+
return failure("Groq", "capacity", "Groq Flex capacity is temporarily unavailable.", "Retry later or use the default service tier.", status, true);
|
|
61
|
+
}
|
|
62
|
+
if (code === "blocked_api_access") {
|
|
63
|
+
return failure("Groq", "billing", "Groq API access is blocked by the organization spend limit.", "Review the Groq organization billing limit before rerunning.", status);
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
function mapGroqError(error) {
|
|
68
|
+
const status = error.statusCode;
|
|
69
|
+
const codeFailure = groqCodeFailure(parseGroqCode(error), status);
|
|
70
|
+
if (codeFailure) {
|
|
71
|
+
return codeFailure;
|
|
72
|
+
}
|
|
73
|
+
const knownStatus = status ? GROQ_STATUS_FAILURES.get(status) : undefined;
|
|
74
|
+
if (knownStatus) {
|
|
75
|
+
return knownStatus();
|
|
76
|
+
}
|
|
77
|
+
if (status === 400 || status === 422 || status === 424) {
|
|
78
|
+
return failure("Groq", "request", "Groq rejected the investigation request.", "Check the selected model and request configuration.", status);
|
|
79
|
+
}
|
|
80
|
+
if (error.isRetryable) {
|
|
81
|
+
return failure("Groq", "unavailable", "Groq could not complete the investigation request.", "Retry after a short delay.", status, true);
|
|
82
|
+
}
|
|
83
|
+
return failure("Groq", "request", "Groq could not complete the investigation request.", "Check the Groq project and model settings.", status);
|
|
84
|
+
}
|
|
85
|
+
const SOLARI_STATUS_FAILURES = new Map([
|
|
86
|
+
[401, () => failure("Solari", "authentication", "Solari rejected the configured API key.", "Replace SOLARI_API_KEY or rerun with --prompt-credentials.", 401)],
|
|
87
|
+
[402, () => failure("Solari", "permission", "The Solari plan does not allow this operation.", "Review the account plan and enabled products in the Solari console.", 402)],
|
|
88
|
+
[403, () => failure("Solari", "permission", "The Solari plan does not allow this operation.", "Review the account plan and enabled products in the Solari console.", 403)],
|
|
89
|
+
[409, () => failure("Solari", "configuration", "A Solari resource is not ready for this operation.", "Resolve the template, snapshot, or idempotency conflict before rerunning.", 409)],
|
|
90
|
+
[429, () => failure("Solari", "concurrency", "The Solari account is at its concurrent-session cap.", "Wait for, pause, or kill an existing session before rerunning.", 429)],
|
|
91
|
+
[501, () => failure("Solari", "configuration", "The requested Solari feature is not configured.", "Choose a supported feature or contact Solari support.", 501)],
|
|
92
|
+
]);
|
|
93
|
+
function solariGatewayFailure(status, code) {
|
|
94
|
+
if (code === "InsufficientCredit") {
|
|
95
|
+
return failure("Solari", "billing", "The Solari account has insufficient prepaid credit.", "Add credit in the Solari console before requesting isolated proof.", status);
|
|
96
|
+
}
|
|
97
|
+
if (code === "ConcurrencyLimitExceeded") {
|
|
98
|
+
return failure("Solari", "concurrency", "The Solari account is at its concurrent-session cap.", "Wait for, pause, or kill an existing session before rerunning.", status);
|
|
99
|
+
}
|
|
100
|
+
if (code === "BrowserUnhealthy") {
|
|
101
|
+
return failure("Solari", "unavailable", "The allocated Solari browser failed its health check.", "Rerun once; the browser SDK will allocate a fresh session.", status || undefined, true);
|
|
102
|
+
}
|
|
103
|
+
if (status === 502 || status === 503 || status === 504) {
|
|
104
|
+
return failure("Solari", "capacity", "Solari infrastructure is temporarily unavailable.", "Retry after a short delay; FlakeLab preserves bounded cleanup.", status, true);
|
|
105
|
+
}
|
|
106
|
+
const knownStatus = SOLARI_STATUS_FAILURES.get(status);
|
|
107
|
+
if (knownStatus) {
|
|
108
|
+
return knownStatus();
|
|
109
|
+
}
|
|
110
|
+
return failure("Solari", "request", "Solari rejected the isolated execution request.", "Check the requested resource and Solari account configuration.", status);
|
|
111
|
+
}
|
|
112
|
+
function mapSolariError(error) {
|
|
113
|
+
if (error instanceof GatewayError) {
|
|
114
|
+
return solariGatewayFailure(error.status, error.code);
|
|
115
|
+
}
|
|
116
|
+
if (error instanceof TimeoutError) {
|
|
117
|
+
return failure("Solari", "timeout", "A Solari operation exceeded its deadline.", "Retry once; if it repeats, inspect Solari service health.", undefined, true);
|
|
118
|
+
}
|
|
119
|
+
if (error instanceof ConnectionError) {
|
|
120
|
+
return failure("Solari", "network", "FlakeLab could not reach the Solari control channel.", "Check connectivity and rerun; no credential change is required.", undefined, true);
|
|
121
|
+
}
|
|
122
|
+
if (error instanceof BrowserSolariError) {
|
|
123
|
+
return solariGatewayFailure(error.status ?? 0, error.code);
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
export async function solariResponseFailure(response) {
|
|
128
|
+
const body = await response.text();
|
|
129
|
+
let code;
|
|
130
|
+
try {
|
|
131
|
+
const parsed = solariErrorSchema.safeParse(JSON.parse(body));
|
|
132
|
+
code = parsed.success ? parsed.data.code : undefined;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
code = undefined;
|
|
136
|
+
}
|
|
137
|
+
return solariGatewayFailure(response.status, code);
|
|
138
|
+
}
|
|
139
|
+
export function normalizeProviderError(error) {
|
|
140
|
+
if (error instanceof ProviderFailure) {
|
|
141
|
+
return error;
|
|
142
|
+
}
|
|
143
|
+
if (RetryError.isInstance(error) && error.lastError instanceof Error) {
|
|
144
|
+
return normalizeProviderError(error.lastError);
|
|
145
|
+
}
|
|
146
|
+
if (APICallError.isInstance(error)) {
|
|
147
|
+
return mapGroqError(error);
|
|
148
|
+
}
|
|
149
|
+
return mapSolariError(error) ?? error;
|
|
150
|
+
}
|
|
151
|
+
export function cliErrorMessage(error) {
|
|
152
|
+
const normalized = normalizeProviderError(error);
|
|
153
|
+
if (!(normalized instanceof ProviderFailure)) {
|
|
154
|
+
return normalized.message;
|
|
155
|
+
}
|
|
156
|
+
const status = normalized.status ? ` · HTTP ${normalized.status}` : "";
|
|
157
|
+
return `${normalized.provider} ${normalized.category}${status}: ${normalized.message}\n${normalized.action}`;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/providers/errors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AAK,UAAU,cAAc,CAAC,IAAY;IAC/C,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
import type { InvestigationReport } from "../investigator/schema.js";
|
|
3
|
+
import type { CandidatePatch } from "./schema.js";
|
|
4
|
+
interface PatchGeneratorOptions {
|
|
5
|
+
investigation: InvestigationReport;
|
|
6
|
+
maxSeconds: number;
|
|
7
|
+
model: LanguageModel;
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare function generateCandidatePatch(options: PatchGeneratorOptions): Promise<CandidatePatch>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { generateText, Output } from "ai";
|
|
2
|
+
import { readSafeTestContext } from "../investigator/safe-source.js";
|
|
3
|
+
import { validateCandidatePatch } from "./policy.js";
|
|
4
|
+
import { candidatePatchSchema } from "./schema.js";
|
|
5
|
+
function patchPrompt(investigation, sources) {
|
|
6
|
+
return [
|
|
7
|
+
"Propose the smallest application-code repair for this experimentally confirmed failure.",
|
|
8
|
+
"Do not edit the selected test, assertions, test configuration, or dependency configuration.",
|
|
9
|
+
"Do not skip errors, add blanket catches, disable lint rules, or merely increase a timeout.",
|
|
10
|
+
"When control flow changes, remove obsolete timers, flags, branches, and write-only state.",
|
|
11
|
+
"The resulting source must pass strict type-aware ESLint with zero warnings.",
|
|
12
|
+
"Each edit must replace one exact, verbatim source substring. Prefer one cohesive edit.",
|
|
13
|
+
"The repair must preserve normal behavior and make the hostile condition pass.",
|
|
14
|
+
"Investigation evidence:",
|
|
15
|
+
JSON.stringify(investigation, null, 2),
|
|
16
|
+
"Bounded local source context:",
|
|
17
|
+
...sources.flatMap((source) => [`--- ${source.path}`, source.content]),
|
|
18
|
+
].join("\n");
|
|
19
|
+
}
|
|
20
|
+
async function requestCandidate(options, prompt) {
|
|
21
|
+
let currentPrompt = prompt;
|
|
22
|
+
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
23
|
+
try {
|
|
24
|
+
const result = await generateText({
|
|
25
|
+
model: options.model,
|
|
26
|
+
output: Output.object({ schema: candidatePatchSchema }),
|
|
27
|
+
prompt: currentPrompt,
|
|
28
|
+
maxOutputTokens: 1_500,
|
|
29
|
+
maxRetries: 2,
|
|
30
|
+
timeout: { totalMs: options.maxSeconds * 1_000 },
|
|
31
|
+
abortSignal: options.signal,
|
|
32
|
+
temperature: 0.2,
|
|
33
|
+
});
|
|
34
|
+
return result.output;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (attempt === 2) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
currentPrompt = [
|
|
41
|
+
prompt,
|
|
42
|
+
"Your previous response did not match the required candidate patch schema.",
|
|
43
|
+
"Return summary, rationale, and 1-3 exact edits with path, before, and after fields.",
|
|
44
|
+
].join("\n");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error("Structured candidate generation exhausted its retry budget");
|
|
48
|
+
}
|
|
49
|
+
export async function generateCandidatePatch(options) {
|
|
50
|
+
const sources = await readSafeTestContext(options.projectRoot, options.investigation.test);
|
|
51
|
+
const allowedPaths = sources.map((source) => source.path);
|
|
52
|
+
let prompt = patchPrompt(options.investigation, sources);
|
|
53
|
+
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
54
|
+
const candidate = await requestCandidate(options, prompt);
|
|
55
|
+
try {
|
|
56
|
+
return await validateCandidatePatch(options.projectRoot, options.investigation.test, allowedPaths, candidate);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (attempt === 2) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
const reason = error instanceof Error ? error.message : "Candidate violated patch policy";
|
|
63
|
+
prompt = [
|
|
64
|
+
prompt,
|
|
65
|
+
"The previous candidate was rejected before execution.",
|
|
66
|
+
`Policy reason: ${reason}`,
|
|
67
|
+
`Rejected candidate: ${JSON.stringify(candidate)}`,
|
|
68
|
+
"Produce a structural application fix that satisfies the original constraints.",
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw new Error("Candidate generation exhausted its revision budget");
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/repair/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAEpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAUlD,SAAS,WAAW,CAAC,aAAkC,EAAE,OAAqB;IAC5E,OAAO;QACL,yFAAyF;QACzF,6FAA6F;QAC7F,4FAA4F;QAC5F,2FAA2F;QAC3F,6EAA6E;QAC7E,wFAAwF;QACxF,+EAA+E;QAC/E,yBAAyB;QACzB,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,+BAA+B;QAC/B,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;KACvE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC7B,OAA8B,EAC9B,MAAc;IAEd,IAAI,aAAa,GAAG,MAAM,CAAA;IAC1B,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE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,CAAC,EAAE,CAAC;QACjD,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACzD,IAAI,CAAC;YACH,OAAO,MAAM,sBAAsB,CACjC,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,aAAa,CAAC,IAAI,EAC1B,YAAY,EACZ,SAAS,CACV,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;gBAClB,MAAM,KAAK,CAAA;YACb,CAAC;YACD,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,iCAAiC,CAAA;YACzF,MAAM,GAAG;gBACP,MAAM;gBACN,uDAAuD;gBACvD,kBAAkB,MAAM,EAAE;gBAC1B,uBAAuB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;gBAClD,+EAA+E;aAChF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACd,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { extname, relative, resolve } from "node:path";
|
|
3
|
+
import { candidatePatchSchema } from "./schema.js";
|
|
4
|
+
const ALLOWED_EXTENSIONS = new Set([".js", ".jsx", ".mjs", ".ts", ".tsx"]);
|
|
5
|
+
const FORBIDDEN_ADDITIONS = [
|
|
6
|
+
"test.skip",
|
|
7
|
+
"test.fixme",
|
|
8
|
+
"test.only",
|
|
9
|
+
"expect.soft",
|
|
10
|
+
"eslint-disable",
|
|
11
|
+
"@ts-ignore",
|
|
12
|
+
"@ts-expect-error",
|
|
13
|
+
];
|
|
14
|
+
const SECRET_ASSIGNMENT = /(?:api[_-]?key|authorization|password|secret|token)\s*[:=]\s*["'][^"']{8,}/iu;
|
|
15
|
+
function normalizedRelativePath(projectRoot, requestedPath) {
|
|
16
|
+
const absolutePath = resolve(projectRoot, requestedPath);
|
|
17
|
+
const pathFromRoot = relative(projectRoot, absolutePath).replaceAll("\\", "/");
|
|
18
|
+
if (pathFromRoot.startsWith("..") || pathFromRoot.includes("node_modules")) {
|
|
19
|
+
throw new Error("Candidate edits must stay inside project source");
|
|
20
|
+
}
|
|
21
|
+
if (!ALLOWED_EXTENSIONS.has(extname(absolutePath).toLowerCase())) {
|
|
22
|
+
throw new Error("Candidate edits are limited to JavaScript and TypeScript source");
|
|
23
|
+
}
|
|
24
|
+
return pathFromRoot;
|
|
25
|
+
}
|
|
26
|
+
function occurrences(content, snippet) {
|
|
27
|
+
let count = 0;
|
|
28
|
+
let index = content.indexOf(snippet);
|
|
29
|
+
while (index >= 0) {
|
|
30
|
+
count += 1;
|
|
31
|
+
index = content.indexOf(snippet, index + snippet.length);
|
|
32
|
+
}
|
|
33
|
+
return count;
|
|
34
|
+
}
|
|
35
|
+
function onlyRaisesNumericLimits(before, after) {
|
|
36
|
+
const beforeNumbers = [...before.matchAll(/\d+/gu)].map((match) => Number(match[0]));
|
|
37
|
+
const afterNumbers = [...after.matchAll(/\d+/gu)].map((match) => Number(match[0]));
|
|
38
|
+
const sameStructure = before.replaceAll(/\d+/gu, "<number>")
|
|
39
|
+
=== after.replaceAll(/\d+/gu, "<number>");
|
|
40
|
+
return sameStructure
|
|
41
|
+
&& beforeNumbers.length > 0
|
|
42
|
+
&& beforeNumbers.length === afterNumbers.length
|
|
43
|
+
&& afterNumbers.some((value, index) => value > beforeNumbers[index]);
|
|
44
|
+
}
|
|
45
|
+
export async function validateCandidatePatch(projectRoot, selectedTest, allowedSourcePaths, value) {
|
|
46
|
+
const candidate = candidatePatchSchema.parse(value);
|
|
47
|
+
const normalizedTest = normalizedRelativePath(projectRoot, selectedTest);
|
|
48
|
+
const allowed = new Set(allowedSourcePaths.map((path) => normalizedRelativePath(projectRoot, path)));
|
|
49
|
+
for (const edit of candidate.edits) {
|
|
50
|
+
const path = normalizedRelativePath(projectRoot, edit.path);
|
|
51
|
+
if (path === normalizedTest || !allowed.has(path)) {
|
|
52
|
+
throw new Error(`Candidate cannot edit unapproved source: ${path}`);
|
|
53
|
+
}
|
|
54
|
+
if (FORBIDDEN_ADDITIONS.some((token) => edit.after.includes(token) && !edit.before.includes(token))) {
|
|
55
|
+
throw new Error(`Candidate introduces a forbidden test-weakening construct in ${path}`);
|
|
56
|
+
}
|
|
57
|
+
if (SECRET_ASSIGNMENT.test(edit.after)) {
|
|
58
|
+
throw new Error(`Candidate introduces a possible credential in ${path}`);
|
|
59
|
+
}
|
|
60
|
+
if (onlyRaisesNumericLimits(edit.before, edit.after)) {
|
|
61
|
+
throw new Error(`Candidate only raises a numeric timing limit in ${path}`);
|
|
62
|
+
}
|
|
63
|
+
const content = await readFile(resolve(projectRoot, path), "utf8");
|
|
64
|
+
if (occurrences(content, edit.before) !== 1) {
|
|
65
|
+
throw new Error(`Candidate edit must match exactly one source location in ${path}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return candidate;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/repair/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;AAC1E,MAAM,mBAAmB,GAAG;IAC1B,WAAW;IACX,YAAY;IACZ,WAAW;IACX,aAAa;IACb,gBAAgB;IA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