Skip to content

Commit 73c16dd

Browse files
mikolalysenkoclaude
andcommitted
fix(test): give four get edge-case fixtures a real file so #158's guard passes
Merged PR #158 (5d7eb6f, "fix(get,scan): retain patch-added new files; guard empty patch records") added a correct guardrail: a fetched patch view whose `files_for_manifest` map is EMPTY is now an exit-1 failure ("patch has no applicable files") instead of a silent `applied:1`. But #158 only touched get.rs and left four tests in get_edge_cases_e2e.rs carrying stale `"files": {}` patch-view fixtures that still assert the `get` succeeds (exit 0). Those four now fail on main: - get_with_id_flag_selects_specific_patch - get_uuid_returns_paid_patch_with_token_succeeds - get_on_vendored_purl_warns_about_uuid_drift - get_uuid_replacing_existing_manifest_entry_reports_updated Their real concern is selection / paid-token / drift-warning / manifest-replacement logic, not "a patch with zero files" — the empty map was only a lazy stand-in. Give each view fixture one recordable net-new file (all-zero `beforeHash`, real git-blob `afterHash` via the shared `common::git_sha256` oracle, matching base64 `blobContent`), modeled on the passing `get_invariants::patch_response_json` fixture, so `files_for_manifest` is non-empty and the guard is satisfied. Every existing assertion (found==1, selected UUID, drift warning, `updated` reporting + `oldUuid`, manifest move) is unchanged. The guardrail in get.rs is untouched. get_edge_cases_e2e now 22/22; lib (350) and get_invariants / get_update_summary (15) unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4f58eec commit 73c16dd

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

crates/socket-patch-cli/tests/get_edge_cases_e2e.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ async fn received_paths(mock: &MockServer) -> Vec<String> {
3232
.collect()
3333
}
3434

35+
/// A single-file patch-view `files` map that survives PR #158's
36+
/// "patch has no applicable files" guardrail (5d7eb6f): a fetched view
37+
/// whose `files_for_manifest` map is empty is now an exit-1 failure, not a
38+
/// silent `applied:1`. The tests below assert SELECTION / paid-token /
39+
/// drift-warning / manifest-replacement behavior — the empty `"files": {}`
40+
/// they used to carry was only ever a lazy stand-in, never the point.
41+
///
42+
/// Modeled on the passing `get_invariants::patch_response_json` fixture: a
43+
/// net-new file with an all-zero `beforeHash`, a real git-blob `afterHash`
44+
/// (via the shared `common::git_sha256` oracle over the decoded blob), and
45+
/// the matching base64 `blobContent`. These tests all pass `--save-only`,
46+
/// which records without verifying content on disk, so one recordable file
47+
/// is enough to make `files_for_manifest` non-empty and clear the guard.
48+
fn single_file_view() -> serde_json::Value {
49+
// base64 "cGF0Y2hlZAo=" decodes to exactly these bytes.
50+
let blob_bytes = b"patched\n";
51+
serde_json::json!({
52+
"package/index.js": {
53+
"beforeHash": "0000000000000000000000000000000000000000000000000000000000000000",
54+
"afterHash": common::git_sha256(blob_bytes),
55+
"blobContent": "cGF0Y2hlZAo=",
56+
}
57+
})
58+
}
59+
3560
#[test]
3661
fn get_one_off_and_save_only_together_errors() {
3762
// The two flags are mutually exclusive — using both must fail.
@@ -100,7 +125,7 @@ async fn get_with_id_flag_selects_specific_patch() {
100125
"uuid": UUID_B,
101126
"purl": purl,
102127
"publishedAt": "2024-02-01T00:00:00Z",
103-
"files": {},
128+
"files": single_file_view(),
104129
"vulnerabilities": {},
105130
"description": "Second patch",
106131
"license": "MIT",
@@ -405,7 +430,7 @@ async fn get_uuid_returns_paid_patch_with_token_succeeds() {
405430
"uuid": UUID_A,
406431
"purl": purl,
407432
"publishedAt": "2024-01-01T00:00:00Z",
408-
"files": {},
433+
"files": single_file_view(),
409434
"vulnerabilities": {},
410435
"description": "Paid patch with token access",
411436
"license": "MIT",
@@ -496,7 +521,7 @@ async fn get_on_vendored_purl_warns_about_uuid_drift() {
496521
"uuid": UUID_B,
497522
"purl": purl,
498523
"publishedAt": "2024-02-01T00:00:00Z",
499-
"files": {},
524+
"files": single_file_view(),
500525
"vulnerabilities": {},
501526
"description": "Newer patch",
502527
"license": "MIT",
@@ -583,7 +608,7 @@ async fn get_uuid_replacing_existing_manifest_entry_reports_updated() {
583608
"uuid": UUID_B,
584609
"purl": purl,
585610
"publishedAt": "2024-02-01T00:00:00Z",
586-
"files": {},
611+
"files": single_file_view(),
587612
"vulnerabilities": {},
588613
"description": "Newer patch for the same purl",
589614
"license": "MIT",

0 commit comments

Comments
 (0)