Skip to content

Commit 008c4cb

Browse files
committed
self-test
1 parent 5798503 commit 008c4cb

3 files changed

Lines changed: 89 additions & 20 deletions

File tree

.github/workflows/self-test.yml

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,54 @@ on:
1010
description: "Fail jobs on assertion mismatch"
1111
type: boolean
1212
default: false
13+
run_baseline:
14+
description: "Run scenario: Baseline — zero calls"
15+
type: boolean
16+
default: true
17+
run_core_5:
18+
description: "Run scenario: 5 core GET calls"
19+
type: boolean
20+
default: true
21+
run_core_10:
22+
description: "Run scenario: 10 core GET calls"
23+
type: boolean
24+
default: true
25+
run_search_2:
26+
description: "Run scenario: 2 search calls"
27+
type: boolean
28+
default: true
29+
run_code_search_2:
30+
description: "Run scenario: 2 code_search calls"
31+
type: boolean
32+
default: true
33+
run_graphql_2:
34+
description: "Run scenario: 2 GraphQL calls"
35+
type: boolean
36+
default: true
37+
run_mixed_small:
38+
description: "Run scenario: Mixed — 2 core + 2 search + 2 graphql"
39+
type: boolean
40+
default: true
41+
run_core_burst:
42+
description: "Run scenario: 5 core GET calls — burst (no sleep)"
43+
type: boolean
44+
default: true
45+
run_search_window_cross:
46+
description: "Run scenario: 2 search calls — 65s apart (window crossing)"
47+
type: boolean
48+
default: true
49+
run_idle_check:
50+
description: "Run scenario: Idle check — no calls, 120s observation"
51+
type: boolean
52+
default: true
53+
run_core_then_search:
54+
description: "Run scenario: 3 core + 2 search (sequential)"
55+
type: boolean
56+
default: true
57+
run_graphql_5:
58+
description: "Run scenario: 5 GraphQL calls"
59+
type: boolean
60+
default: true
1361

1462
concurrency:
1563
group: self-test
@@ -18,6 +66,7 @@ concurrency:
1866
jobs:
1967
baseline:
2068
runs-on: ubuntu-latest
69+
if: ${{ inputs.run_baseline }}
2170
steps:
2271
- uses: actions/checkout@v4
2372

@@ -53,7 +102,7 @@ jobs:
53102
core-5:
54103
runs-on: ubuntu-latest
55104
needs: [baseline-diag, baseline]
56-
if: ${{ always() }}
105+
if: ${{ always() && inputs.run_core_5 }}
57106
steps:
58107
- uses: actions/checkout@v4
59108

@@ -180,7 +229,7 @@ jobs:
180229
core-10:
181230
runs-on: ubuntu-latest
182231
needs: [core-5-diag, core-5]
183-
if: ${{ always() }}
232+
if: ${{ always() && inputs.run_core_10 }}
184233
steps:
185234
- uses: actions/checkout@v4
186235

@@ -307,7 +356,7 @@ jobs:
307356
search-2:
308357
runs-on: ubuntu-latest
309358
needs: [core-10-diag, core-10]
310-
if: ${{ always() }}
359+
if: ${{ always() && inputs.run_search_2 }}
311360
steps:
312361
- uses: actions/checkout@v4
313362

@@ -434,7 +483,7 @@ jobs:
434483
code-search-2:
435484
runs-on: ubuntu-latest
436485
needs: [search-2-diag, search-2]
437-
if: ${{ always() }}
486+
if: ${{ always() && inputs.run_code_search_2 }}
438487
steps:
439488
- uses: actions/checkout@v4
440489

@@ -501,7 +550,7 @@ jobs:
501550
state = json.load(f)
502551
buckets = state.get('buckets', {})
503552
expectations = {
504-
'code_search': {'delta': 2, 'max_windows': 0}
553+
'code_search': {'delta': 2, 'min_windows': 1}
505554
}
506555
results = [] # list of (bucket, check_name, passed, detail)
507556
for bucket_name, expect in expectations.items():
@@ -561,7 +610,7 @@ jobs:
561610
graphql-2:
562611
runs-on: ubuntu-latest
563612
needs: [code-search-2-diag, code-search-2]
564-
if: ${{ always() }}
613+
if: ${{ always() && inputs.run_graphql_2 }}
565614
steps:
566615
- uses: actions/checkout@v4
567616

@@ -690,7 +739,7 @@ jobs:
690739
mixed-small:
691740
runs-on: ubuntu-latest
692741
needs: [graphql-2-diag, graphql-2]
693-
if: ${{ always() }}
742+
if: ${{ always() && inputs.run_mixed_small }}
694743
steps:
695744
- uses: actions/checkout@v4
696745

@@ -843,7 +892,7 @@ jobs:
843892
core-burst:
844893
runs-on: ubuntu-latest
845894
needs: [mixed-small-diag, mixed-small]
846-
if: ${{ always() }}
895+
if: ${{ always() && inputs.run_core_burst }}
847896
steps:
848897
- uses: actions/checkout@v4
849898

@@ -969,7 +1018,7 @@ jobs:
9691018
search-window-cross:
9701019
runs-on: ubuntu-latest
9711020
needs: [core-burst-diag, core-burst]
972-
if: ${{ always() }}
1021+
if: ${{ always() && inputs.run_search_window_cross }}
9731022
steps:
9741023
- uses: actions/checkout@v4
9751024

@@ -1096,7 +1145,7 @@ jobs:
10961145
idle-check:
10971146
runs-on: ubuntu-latest
10981147
needs: [search-window-cross-diag, search-window-cross]
1099-
if: ${{ always() }}
1148+
if: ${{ always() && inputs.run_idle_check }}
11001149
steps:
11011150
- uses: actions/checkout@v4
11021151

@@ -1132,7 +1181,7 @@ jobs:
11321181
core-then-search:
11331182
runs-on: ubuntu-latest
11341183
needs: [idle-check-diag, idle-check]
1135-
if: ${{ always() }}
1184+
if: ${{ always() && inputs.run_core_then_search }}
11361185
steps:
11371186
- uses: actions/checkout@v4
11381187

@@ -1271,7 +1320,7 @@ jobs:
12711320
graphql-5:
12721321
runs-on: ubuntu-latest
12731322
needs: [core-then-search-diag, core-then-search]
1274-
if: ${{ always() }}
1323+
if: ${{ always() && inputs.run_graphql_5 }}
12751324
steps:
12761325
- uses: actions/checkout@v4
12771326

scripts/generate-self-test.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
2020
const outputPath = join(__dirname, "..", ".github", "workflows", "self-test.yml");
2121
const ARTIFACT_PREFIX = "github-api-usage-monitor";
2222

23+
function scenarioInputName(id: string): string {
24+
return `run_${id.replace(/-/g, "_")}`;
25+
}
26+
2327
// ---------------------------------------------------------------------------
2428
// Helpers
2529
// ---------------------------------------------------------------------------
@@ -201,15 +205,19 @@ function generateJob(
201205
previousScenarioId: string | null
202206
): string {
203207
const lines: string[] = [];
208+
const runInput = scenarioInputName(scenario.id);
204209

205210
lines.push(`${scenario.id}:`);
206211
lines.push(` runs-on: ubuntu-latest`);
212+
if (previousId === null) {
213+
lines.push(` if: \${{ inputs.${runInput} }}`);
214+
}
207215
if (previousId !== null) {
208216
const needs = previousScenarioId
209217
? `[${previousId}, ${previousScenarioId}]`
210218
: `[${previousId}]`;
211219
lines.push(` needs: ${needs}`);
212-
lines.push(` if: \${{ always() }}`);
220+
lines.push(` if: \${{ always() && inputs.${runInput} }}`);
213221
}
214222
lines.push(` steps:`);
215223
lines.push(` - uses: actions/checkout@v4`);
@@ -307,18 +315,30 @@ function generateDiagnosticsJob(scenario: Scenario): string {
307315
// ---------------------------------------------------------------------------
308316

309317
function generateWorkflow(): string {
318+
const inputLines: string[] = [
319+
" workflow_dispatch:",
320+
" inputs:",
321+
" strict_validation:",
322+
" description: \"Fail jobs on assertion mismatch\"",
323+
" type: boolean",
324+
" default: false",
325+
];
326+
327+
for (const scenario of SCENARIOS) {
328+
const inputName = scenarioInputName(scenario.id);
329+
inputLines.push(` ${inputName}:`);
330+
inputLines.push(` description: "Run scenario: ${yamlEscape(scenario.name)}"`);
331+
inputLines.push(` type: boolean`);
332+
inputLines.push(` default: true`);
333+
}
334+
310335
const header = `# AUTO-GENERATED by scripts/generate-self-test.ts — do not edit manually
311336
# Regenerate: npx tsx scripts/generate-self-test.ts
312337
313338
name: Self-Test
314339
315340
on:
316-
workflow_dispatch:
317-
inputs:
318-
strict_validation:
319-
description: "Fail jobs on assertion mismatch"
320-
type: boolean
321-
default: false
341+
${inputLines.join("\n")}
322342
323343
concurrency:
324344
group: self-test

scripts/scenarios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const SCENARIOS: Scenario[] = [
153153
inter_call_sleep_s: 3,
154154
poll_duration_s: 90,
155155
expected: {
156-
code_search: { total_used_delta: 2, windows_crossed_max: 0 },
156+
code_search: { total_used_delta: 2, windows_crossed_min: 1 },
157157
},
158158
},
159159

0 commit comments

Comments
 (0)