Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions crates/socket-patch-cli/tests/get_edge_cases_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ async fn received_paths(mock: &MockServer) -> Vec<String> {
.collect()
}

/// A single-file patch-view `files` map that survives PR #158's
/// "patch has no applicable files" guardrail (5d7eb6f): a fetched view
/// whose `files_for_manifest` map is empty is now an exit-1 failure, not a
/// silent `applied:1`. The tests below assert SELECTION / paid-token /
/// drift-warning / manifest-replacement behavior — the empty `"files": {}`
/// they used to carry was only ever a lazy stand-in, never the point.
///
/// Modeled on the passing `get_invariants::patch_response_json` fixture: a
/// net-new file with an all-zero `beforeHash`, a real git-blob `afterHash`
/// (via the shared `common::git_sha256` oracle over the decoded blob), and
/// the matching base64 `blobContent`. These tests all pass `--save-only`,
/// which records without verifying content on disk, so one recordable file
/// is enough to make `files_for_manifest` non-empty and clear the guard.
fn single_file_view() -> serde_json::Value {
// base64 "cGF0Y2hlZAo=" decodes to exactly these bytes.
let blob_bytes = b"patched\n";
serde_json::json!({
"package/index.js": {
"beforeHash": "0000000000000000000000000000000000000000000000000000000000000000",
"afterHash": common::git_sha256(blob_bytes),
"blobContent": "cGF0Y2hlZAo=",
}
})
}

#[test]
fn get_one_off_and_save_only_together_errors() {
// The two flags are mutually exclusive — using both must fail.
Expand Down Expand Up @@ -100,7 +125,7 @@ async fn get_with_id_flag_selects_specific_patch() {
"uuid": UUID_B,
"purl": purl,
"publishedAt": "2024-02-01T00:00:00Z",
"files": {},
"files": single_file_view(),
"vulnerabilities": {},
"description": "Second patch",
"license": "MIT",
Expand Down Expand Up @@ -405,7 +430,7 @@ async fn get_uuid_returns_paid_patch_with_token_succeeds() {
"uuid": UUID_A,
"purl": purl,
"publishedAt": "2024-01-01T00:00:00Z",
"files": {},
"files": single_file_view(),
"vulnerabilities": {},
"description": "Paid patch with token access",
"license": "MIT",
Expand Down Expand Up @@ -496,7 +521,7 @@ async fn get_on_vendored_purl_warns_about_uuid_drift() {
"uuid": UUID_B,
"purl": purl,
"publishedAt": "2024-02-01T00:00:00Z",
"files": {},
"files": single_file_view(),
"vulnerabilities": {},
"description": "Newer patch",
"license": "MIT",
Expand Down Expand Up @@ -583,7 +608,7 @@ async fn get_uuid_replacing_existing_manifest_entry_reports_updated() {
"uuid": UUID_B,
"purl": purl,
"publishedAt": "2024-02-01T00:00:00Z",
"files": {},
"files": single_file_view(),
"vulnerabilities": {},
"description": "Newer patch for the same purl",
"license": "MIT",
Expand Down
11 changes: 10 additions & 1 deletion crates/socket-patch-cli/tests/telemetry_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,16 @@ async fn get_emits_patch_fetched_telemetry_on_uuid_lookup_success() {
"publishedAt": "2024-06-01T00:00:00Z",
"license": "MIT",
"description": "test patch",
"files": {},
// A recordable new-file patch (afterHash is the git-blob sha256 of
// the decoded blobContent "patched\n"). Post-#158, a patch whose
// applicable-files map is empty is a hard failure ("no applicable
// files"), so the success path this test asserts needs a real file.
"files": {
"package/index.js": {
"afterHash": "d2802877eb1c2f442d30d18abcb281cb2830875571624544f2f1acb36480997e",
"blobContent": "cGF0Y2hlZAo=",
}
},
"vulnerabilities": {},
});
let mock = setup_mock(
Expand Down
Loading