Skip to content

Commit 7981d71

Browse files
authored
test(threat-network): repair time-sensitive CI coverage (#149)
1 parent cec6a1c commit 7981d71

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

.github/workflows/trusted-repository-sanitation.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ jobs:
3838
VEDETTA_BASE_REF: ${{ github.event.pull_request.base.ref }}
3939
VEDETTA_BASE_SHA: ${{ github.event.pull_request.base.sha }}
4040
VEDETTA_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
41-
VEDETTA_MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
41+
# GitHub may leave merge_commit_sha empty for a newly opened PR even
42+
# when refs/pull/N/merge already exists. The trusted runner fetches
43+
# and verifies that merge ref against the pinned base/head itself;
44+
# the head SHA here is therefore a non-empty, validated fallback for
45+
# its required event-shape input, not a substitute merge tree.
46+
VEDETTA_MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.head.sha }}
4247
run: bash scripts/run-trusted-pr-sanitation.sh

scripts/tests/trusted-pr-sanitation-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ ok grep -Fq 'run: bash scripts/run-trusted-pr-sanitation.sh' "$WORKFLOW" "truste
411411
# alternate YAML spellings such as quoted keys, flow mappings, anchors, and
412412
# aliases that text-only step counts cannot interpret safely.
413413
is "$(file_sha256 "$WORKFLOW")" \
414-
"2d54052e13e715e6353ca9cee405a41e88c6b4f5dbe94e69ff4558a806953f44" \
414+
"dfffa7eaacf6ebf20b00d34b07868bf12a32d1768923762c237eab8ed5f2ce40" \
415415
"trusted workflow matches the exact reviewed definition"
416416
ok workflow_has_no_writable_permissions "$WORKFLOW" "trusted workflow grants no writable permission"
417417
is "$(grep -Ec '^[[:space:]]*(-[[:space:]]*)?uses:' "$WORKFLOW")" \

threat-network/internal/api/api_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,22 @@ func signAndPost(t *testing.T, ts *httptest.Server, id, key, nonce string, body
237237
}
238238

239239
func batchBody(batchID string) []byte {
240+
// Consensus intentionally considers only a trailing window. Keep this fixture
241+
// inside that window instead of pinning it to the date the test was written.
242+
bucket := time.Now().UTC().Truncate(time.Hour)
243+
generatedAt := bucket.Add(15 * time.Minute)
240244
return []byte(fmt.Sprintf(`{
241-
"schema_version":1,"batch_id":%q,"generated_at":"2026-07-03T14:15:02Z",
242-
"window_start":"2026-07-03T14:00:00Z","window_end":"2026-07-03T15:00:00Z","signals":[
243-
{"signal_id":"s1","kind":"known_bad_domain_hit","time_bucket":"2026-07-03T14:00:00Z",
245+
"schema_version":1,"batch_id":%q,"generated_at":%q,
246+
"window_start":%q,"window_end":%q,"signals":[
247+
{"signal_id":"s1","kind":"known_bad_domain_hit","time_bucket":%q,
244248
"domain":"c2.badzone.example","etld_plus_one":"badzone.example","local_confidence":0.99,
245249
"local_reasons":["known_bad"],"observation_count":4,"distinct_asset_count":2,"blocked_count":4}
246-
]}`, batchID))
250+
]}`,
251+
batchID,
252+
generatedAt.Format(time.RFC3339),
253+
bucket.Format(time.RFC3339),
254+
bucket.Add(time.Hour).Format(time.RFC3339),
255+
bucket.Format(time.RFC3339)))
247256
}
248257

249258
func TestEndToEndRegisterIngestConsensusFeed(t *testing.T) {

threat-network/internal/store/corpus_publication_invariants_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestCorpusPublishRejectsStoredCrossProfilePredecessor(t *testing.T) {
6161
t.Fatal(err)
6262
}
6363
baseVariantID := base.Variants[0].VariantID
64-
base, err = db.PublishCorpusProfile(context.Background(), base.ProfileID, corpusPublishRequest(0),
64+
_, err = db.PublishCorpusProfile(context.Background(), base.ProfileID, corpusPublishRequest(0),
6565
CorpusMutation{ExpectedETag: base.ETag})
6666
if err != nil {
6767
t.Fatal(err)

threat-network/internal/store/corpus_rows_resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestCorpusReadErrorsReleaseSingleConnection(t *testing.T) {
7878
if err != nil {
7979
t.Fatal(err)
8080
}
81-
profile, err = db.PublishCorpusProfile(context.Background(), profile.ProfileID, corpusPublishRequest(0),
81+
_, err = db.PublishCorpusProfile(context.Background(), profile.ProfileID, corpusPublishRequest(0),
8282
CorpusMutation{ExpectedETag: profile.ETag})
8383
if err != nil {
8484
t.Fatal(err)

threat-network/internal/store/corpus_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ func TestCorpusDraftPublishRevisionAndImmutableRelease(t *testing.T) {
695695
if manifest.CorpusRevision != 1 || string(stillOne) != string(releaseOneBytes) {
696696
t.Fatal("draft revision changed the public release")
697697
}
698-
profile, err = db.PublishCorpusProfile(context.Background(), profile.ProfileID, corpusPublishRequest(1), CorpusMutation{ExpectedETag: profile.ETag})
698+
_, err = db.PublishCorpusProfile(context.Background(), profile.ProfileID, corpusPublishRequest(1), CorpusMutation{ExpectedETag: profile.ETag})
699699
if err != nil {
700700
t.Fatal(err)
701701
}
@@ -1196,7 +1196,7 @@ func TestCorpusAbandonedUnpublishedVariantCanRestartIdentity(t *testing.T) {
11961196
if got == nil || got.VariantID != childID || got.PredecessorVariantID != "" || got.Draft == nil || got.Draft.Revision != 2 {
11971197
t.Fatalf("abandoned identity was not safely restarted: %+v", got)
11981198
}
1199-
profile, err = db.PublishCorpusProfile(context.Background(), profile.ProfileID,
1199+
_, err = db.PublishCorpusProfile(context.Background(), profile.ProfileID,
12001200
corpusPublishRequest(0), CorpusMutation{ExpectedETag: profile.ETag})
12011201
if err != nil {
12021202
t.Fatal(err)

0 commit comments

Comments
 (0)