파일 스냅샷 공개 API 회귀를 추가함
- 작성자
- 코노모리 카논
- 작성 시각
- 커밋
b6521d55061c721c2a9102b39533ad941a910010- 부모
- b7c3d55
변경된 파일 13개
+1,782-0| @@ -0,0 +1,102 @@ | ||
| 1 | 추가: # This file is automatically @generated by Cargo. | |
| 2 | 추가: # It is not intended for manual editing. | |
| 3 | 추가: version = 4 | |
| 4 | 추가: | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "block-buffer" | |
| 7 | 추가: version = "0.10.4" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | |
| 10 | 추가: dependencies = [ | |
| 11 | 추가: "generic-array", | |
| 12 | 추가: ] | |
| 13 | 추가: | |
| 14 | 추가: [[package]] | |
| 15 | 추가: name = "cfg-if" | |
| 16 | 추가: version = "1.0.5" | |
| 17 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 18 | 추가: checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | |
| 19 | 추가: | |
| 20 | 추가: [[package]] | |
| 21 | 추가: name = "cpufeatures" | |
| 22 | 추가: version = "0.2.17" | |
| 23 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 24 | 추가: checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | |
| 25 | 추가: dependencies = [ | |
| 26 | 추가: "libc", | |
| 27 | 추가: ] | |
| 28 | 추가: | |
| 29 | 추가: [[package]] | |
| 30 | 추가: name = "crypto-common" | |
| 31 | 추가: version = "0.1.7" | |
| 32 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 33 | 추가: checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" | |
| 34 | 추가: dependencies = [ | |
| 35 | 추가: "generic-array", | |
| 36 | 추가: "typenum", | |
| 37 | 추가: ] | |
| 38 | 추가: | |
| 39 | 추가: [[package]] | |
| 40 | 추가: name = "digest" | |
| 41 | 추가: version = "0.10.7" | |
| 42 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 43 | 추가: checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | |
| 44 | 추가: dependencies = [ | |
| 45 | 추가: "block-buffer", | |
| 46 | 추가: "crypto-common", | |
| 47 | 추가: ] | |
| 48 | 추가: | |
| 49 | 추가: [[package]] | |
| 50 | 추가: name = "generic-array" | |
| 51 | 추가: version = "0.14.7" | |
| 52 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 53 | 추가: checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | |
| 54 | 추가: dependencies = [ | |
| 55 | 추가: "typenum", | |
| 56 | 추가: "version_check", | |
| 57 | 추가: ] | |
| 58 | 추가: | |
| 59 | 추가: [[package]] | |
| 60 | 추가: name = "libc" | |
| 61 | 추가: version = "0.2.191" | |
| 62 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 63 | 추가: checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" | |
| 64 | 추가: | |
| 65 | 추가: [[package]] | |
| 66 | 추가: name = "sha2" | |
| 67 | 추가: version = "0.10.9" | |
| 68 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 69 | 추가: checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" | |
| 70 | 추가: dependencies = [ | |
| 71 | 추가: "cfg-if", | |
| 72 | 추가: "cpufeatures", | |
| 73 | 추가: "digest", | |
| 74 | 추가: ] | |
| 75 | 추가: | |
| 76 | 추가: [[package]] | |
| 77 | 추가: name = "typenum" | |
| 78 | 추가: version = "1.20.1" | |
| 79 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 80 | 추가: checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 81 | 추가: | |
| 82 | 추가: [[package]] | |
| 83 | 추가: name = "version_check" | |
| 84 | 추가: version = "0.9.5" | |
| 85 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 86 | 추가: checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | |
| 87 | 추가: | |
| 88 | 추가: [[package]] | |
| 89 | 추가: name = "zipelo-file-snapshot" | |
| 90 | 추가: version = "0.1.0" | |
| 91 | 추가: dependencies = [ | |
| 92 | 추가: "libc", | |
| 93 | 추가: "sha2", | |
| 94 | 추가: ] | |
| 95 | 추가: | |
| 96 | 추가: [[package]] | |
| 97 | 추가: name = "zipelo-file-snapshot-regressions" | |
| 98 | 추가: version = "0.1.0" | |
| 99 | 추가: dependencies = [ | |
| 100 | 추가: "libc", | |
| 101 | 추가: "zipelo-file-snapshot", | |
| 102 | 추가: ] |
| @@ -0,0 +1,20 @@ | ||
| 1 | 추가: [package] | |
| 2 | 추가: name = "zipelo-file-snapshot-regressions" | |
| 3 | 추가: version = "0.1.0" | |
| 4 | 추가: edition = "2024" | |
| 5 | 추가: rust-version = "1.99" | |
| 6 | 추가: license = "MIT" | |
| 7 | 추가: publish = false | |
| 8 | 추가: autotests = false | |
| 9 | 추가: autoexamples = false | |
| 10 | 추가: autobenches = false | |
| 11 | 추가: | |
| 12 | 추가: [[test]] | |
| 13 | 추가: name = "snapshot_public_api" | |
| 14 | 추가: path = "main.rs" | |
| 15 | 추가: | |
| 16 | 추가: [dependencies] | |
| 17 | 추가: snapshot = { package = "zipelo-file-snapshot", path = "../../experiments/rust-file-snapshot" } | |
| 18 | 추가: libc = { version = "=0.2.191", default-features = false, features = ["std"] } | |
| 19 | 추가: | |
| 20 | 추가: [workspace] |
| @@ -0,0 +1,12 @@ | ||
| 1 | 추가: 2dd86687bc8613e2c59b22fd59b433e10f9a8b855ebfd04a582007234080e83a Cargo.lock | |
| 2 | 추가: 33cb8190edc30437576f2266644d4cad9ff1cf77f590e795d6602fa0377c95e2 Cargo.toml | |
| 3 | 추가: 1e79a6a86ad505593089a69675ae425afe3841c990d60afba359d252c8893906 boundaries.rs | |
| 4 | 추가: 070de4c064bce0f2accce815e19d93d8acf3a9569c21fa2b6e95e0f323cb2284 contract.json | |
| 5 | 추가: fb2d014bdba4e799f9f2d5e52a825bee4ba698e519bcc17524b305b0c7dcbac3 control.rs | |
| 6 | 추가: ba7671882fa9ed4cdb1ad66aafa733bcb8f04562cf75862302e205226622b9ce main.rs | |
| 7 | 추가: 4f8aa79cd8395952872a379146d87d62e801f76ab7dace1ecb3874b2684e1bcf mutations.rs | |
| 8 | 추가: 3311c3b3fb7bfab8b2ed21a321381a7ac788237d5270f93b481ff76ecc80667a paths.rs | |
| 9 | 추가: 07c7697ddacd9689cffb094cc9edcbe56d523af669986454944cbf27e8eab8cb source-pins.json | |
| 10 | 추가: 424745cf6f6a136410d313b4a8cefe7c190073b134ef1c6dc85e5b40688a8722 static_check.py | |
| 11 | 추가: ef38ac3975b593e03130f81293130d9468bebbdbd3d8f128e44db9c74756bd13 static_check_helper_tests.py | |
| 12 | 추가: cfaae5d310eeb3e5e1e60d7f7700ae3df3646a39a7bdbaf3e16f6f4725ac400c support.rs |
| @@ -0,0 +1,289 @@ | ||
| 1 | 추가: use crate::support::*; | |
| 2 | 추가: use snapshot::{Error, LimitKind, Limits, MAX_BYTES, MAX_IO_BYTES, MAX_READ_CALLS}; | |
| 3 | 추가: use std::{fs, os::unix::fs::MetadataExt, path::Path, time::Duration}; | |
| 4 | 추가: | |
| 5 | 추가: fn boundary(length: usize) { | |
| 6 | 추가: let sandbox = Sandbox::new(); | |
| 7 | 추가: let bytes = pattern(length); | |
| 8 | 추가: let path = sandbox.file("input", &bytes); | |
| 9 | 추가: let before = fs::metadata(&path).unwrap(); | |
| 10 | 추가: let result = get(&path, Limits::default()).unwrap(); | |
| 11 | 추가: assert_eq!(result.bytes(), bytes); | |
| 12 | 추가: assert_eq!(result.identity().length(), length as u64); | |
| 13 | 추가: assert_eq!(result.identity().device(), before.dev()); | |
| 14 | 추가: assert_eq!(result.identity().inode(), before.ino()); | |
| 15 | 추가: assert_eq!(result.identity().links(), 1); | |
| 16 | 추가: assert_eq!(result.identity().mode(), before.mode()); | |
| 17 | 추가: assert_eq!( | |
| 18 | 추가: result.identity().modified(), | |
| 19 | 추가: (before.mtime(), before.mtime_nsec()) | |
| 20 | 추가: ); | |
| 21 | 추가: assert_eq!( | |
| 22 | 추가: result.identity().changed(), | |
| 23 | 추가: (before.ctime(), before.ctime_nsec()) | |
| 24 | 추가: ); | |
| 25 | 추가: expect_usage(&result, length); | |
| 26 | 추가: assert_eq!(result.into_bytes(), bytes); | |
| 27 | 추가: assert_eq!(fs::read(&path).unwrap(), bytes); | |
| 28 | 추가: sandbox.finish(); | |
| 29 | 추가: } | |
| 30 | 추가: | |
| 31 | 추가: #[test] | |
| 32 | 추가: fn empty() { | |
| 33 | 추가: boundary(0); | |
| 34 | 추가: } | |
| 35 | 추가: | |
| 36 | 추가: #[test] | |
| 37 | 추가: fn one() { | |
| 38 | 추가: boundary(1); | |
| 39 | 추가: } | |
| 40 | 추가: | |
| 41 | 추가: #[test] | |
| 42 | 추가: fn chunk_minus_one() { | |
| 43 | 추가: boundary(65535); | |
| 44 | 추가: } | |
| 45 | 추가: | |
| 46 | 추가: #[test] | |
| 47 | 추가: fn chunk() { | |
| 48 | 추가: boundary(65536); | |
| 49 | 추가: } | |
| 50 | 추가: | |
| 51 | 추가: #[test] | |
| 52 | 추가: fn chunk_plus_one() { | |
| 53 | 추가: boundary(65537); | |
| 54 | 추가: } | |
| 55 | 추가: | |
| 56 | 추가: #[test] | |
| 57 | 추가: fn maximum_minus_one() { | |
| 58 | 추가: boundary(16777215); | |
| 59 | 추가: } | |
| 60 | 추가: | |
| 61 | 추가: #[test] | |
| 62 | 추가: fn maximum() { | |
| 63 | 추가: boundary(16777216); | |
| 64 | 추가: } | |
| 65 | 추가: | |
| 66 | 추가: #[test] | |
| 67 | 추가: fn sha256_known_abc_and_debug_redaction() { | |
| 68 | 추가: let sandbox = Sandbox::new(); | |
| 69 | 추가: let path = sandbox.file("private-input-marker", b"abc"); | |
| 70 | 추가: let result = get(&path, Limits::default()).unwrap(); | |
| 71 | 추가: assert_eq!( | |
| 72 | 추가: result.sha256(), | |
| 73 | 추가: [ | |
| 74 | 추가: 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, | |
| 75 | 추가: 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, | |
| 76 | 추가: 0xf2, 0x00, 0x15, 0xad, | |
| 77 | 추가: ] | |
| 78 | 추가: ); | |
| 79 | 추가: let debug = format!("{result:?}"); | |
| 80 | 추가: for secret in ["private-input-marker", "abc", "sha256", "identity"] { | |
| 81 | 추가: assert!(!debug.contains(secret)); | |
| 82 | 추가: } | |
| 83 | 추가: sandbox.finish(); | |
| 84 | 추가: } | |
| 85 | 추가: | |
| 86 | 추가: fn invalid(limits: Limits) { | |
| 87 | 추가: let mut called = false; | |
| 88 | 추가: let result = snapshot::capture( | |
| 89 | 추가: snapshot::Request { | |
| 90 | 추가: path: Path::new(""), | |
| 91 | 추가: limits, | |
| 92 | 추가: }, | |
| 93 | 추가: |_| { | |
| 94 | 추가: called = true; | |
| 95 | 추가: Err(snapshot::Stop::<()>::Cancelled) | |
| 96 | 추가: }, | |
| 97 | 추가: ) | |
| 98 | 추가: .unwrap_err(); | |
| 99 | 추가: assert!(matches!(result.cause, Error::InvalidLimits)); | |
| 100 | 추가: assert_eq!(result.usage, snapshot::Usage::default()); | |
| 101 | 추가: assert!(!called); | |
| 102 | 추가: } | |
| 103 | 추가: | |
| 104 | 추가: #[test] | |
| 105 | 추가: fn invalid_bytes_cap() { | |
| 106 | 추가: invalid(Limits { | |
| 107 | 추가: max_bytes: MAX_BYTES + 1, | |
| 108 | 추가: ..Limits::default() | |
| 109 | 추가: }); | |
| 110 | 추가: } | |
| 111 | 추가: | |
| 112 | 추가: #[test] | |
| 113 | 추가: fn invalid_io_cap() { | |
| 114 | 추가: invalid(Limits { | |
| 115 | 추가: max_io_bytes: MAX_IO_BYTES + 1, | |
| 116 | 추가: ..Limits::default() | |
| 117 | 추가: }); | |
| 118 | 추가: } | |
| 119 | 추가: | |
| 120 | 추가: #[test] | |
| 121 | 추가: fn invalid_calls_zero() { | |
| 122 | 추가: invalid(Limits { | |
| 123 | 추가: max_read_calls: 0, | |
| 124 | 추가: ..Limits::default() | |
| 125 | 추가: }); | |
| 126 | 추가: } | |
| 127 | 추가: | |
| 128 | 추가: #[test] | |
| 129 | 추가: fn invalid_calls_cap() { | |
| 130 | 추가: invalid(Limits { | |
| 131 | 추가: max_read_calls: MAX_READ_CALLS + 1, | |
| 132 | 추가: ..Limits::default() | |
| 133 | 추가: }); | |
| 134 | 추가: } | |
| 135 | 추가: | |
| 136 | 추가: #[test] | |
| 137 | 추가: fn invalid_deadline_zero() { | |
| 138 | 추가: invalid(Limits { | |
| 139 | 추가: max_duration: Duration::ZERO, | |
| 140 | 추가: ..Limits::default() | |
| 141 | 추가: }); | |
| 142 | 추가: } | |
| 143 | 추가: | |
| 144 | 추가: #[test] | |
| 145 | 추가: fn invalid_deadline_cap() { | |
| 146 | 추가: invalid(Limits { | |
| 147 | 추가: max_duration: Duration::from_secs(301), | |
| 148 | 추가: ..Limits::default() | |
| 149 | 추가: }); | |
| 150 | 추가: } | |
| 151 | 추가: | |
| 152 | 추가: #[test] | |
| 153 | 추가: fn source_over_maximum_rejected_before_data_open() { | |
| 154 | 추가: let sandbox = Sandbox::new(); | |
| 155 | 추가: let path = sandbox.file("input", &pattern(MAX_BYTES as usize + 1)); | |
| 156 | 추가: let failure = get(&path, Limits::default()).unwrap_err(); | |
| 157 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::Bytes))); | |
| 158 | 추가: assert_eq!(failure.usage.open_calls, 1); | |
| 159 | 추가: assert_eq!(failure.usage.metadata_calls, 1); | |
| 160 | 추가: assert_eq!(failure.usage.read_calls, 0); | |
| 161 | 추가: sandbox.finish(); | |
| 162 | 추가: } | |
| 163 | 추가: | |
| 164 | 추가: #[test] | |
| 165 | 추가: fn empty_accepts_zero_byte_limit_with_exact_eof_budget() { | |
| 166 | 추가: let sandbox = Sandbox::new(); | |
| 167 | 추가: let path = sandbox.file("input", b""); | |
| 168 | 추가: let result = get( | |
| 169 | 추가: &path, | |
| 170 | 추가: Limits { | |
| 171 | 추가: max_bytes: 0, | |
| 172 | 추가: max_io_bytes: 2, | |
| 173 | 추가: max_read_calls: 2, | |
| 174 | 추가: ..Limits::default() | |
| 175 | 추가: }, | |
| 176 | 추가: ) | |
| 177 | 추가: .unwrap(); | |
| 178 | 추가: expect_usage(&result, 0); | |
| 179 | 추가: sandbox.finish(); | |
| 180 | 추가: } | |
| 181 | 추가: | |
| 182 | 추가: #[test] | |
| 183 | 추가: fn nonempty_rejects_zero_byte_limit() { | |
| 184 | 추가: let sandbox = Sandbox::new(); | |
| 185 | 추가: let path = sandbox.file("input", b"x"); | |
| 186 | 추가: let failure = get( | |
| 187 | 추가: &path, | |
| 188 | 추가: Limits { | |
| 189 | 추가: max_bytes: 0, | |
| 190 | 추가: ..Limits::default() | |
| 191 | 추가: }, | |
| 192 | 추가: ) | |
| 193 | 추가: .unwrap_err(); | |
| 194 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::Bytes))); | |
| 195 | 추가: assert_eq!(failure.usage.read_calls, 0); | |
| 196 | 추가: sandbox.finish(); | |
| 197 | 추가: } | |
| 198 | 추가: | |
| 199 | 추가: #[test] | |
| 200 | 추가: fn zero_io_budget_is_valid_but_cannot_probe_eof() { | |
| 201 | 추가: let sandbox = Sandbox::new(); | |
| 202 | 추가: let path = sandbox.file("input", b""); | |
| 203 | 추가: let failure = get( | |
| 204 | 추가: &path, | |
| 205 | 추가: Limits { | |
| 206 | 추가: max_io_bytes: 0, | |
| 207 | 추가: ..Limits::default() | |
| 208 | 추가: }, | |
| 209 | 추가: ) | |
| 210 | 추가: .unwrap_err(); | |
| 211 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::IoBytes))); | |
| 212 | 추가: assert_eq!(failure.usage.read_calls, 0); | |
| 213 | 추가: assert_eq!(failure.usage.reserved_read_bytes, 0); | |
| 214 | 추가: sandbox.finish(); | |
| 215 | 추가: } | |
| 216 | 추가: | |
| 217 | 추가: #[test] | |
| 218 | 추가: fn exact_io_and_call_budget_includes_both_eof_probes() { | |
| 219 | 추가: let sandbox = Sandbox::new(); | |
| 220 | 추가: let path = sandbox.file("input", &pattern(65_537)); | |
| 221 | 추가: let result = get( | |
| 222 | 추가: &path, | |
| 223 | 추가: Limits { | |
| 224 | 추가: max_io_bytes: 131_076, | |
| 225 | 추가: max_read_calls: 6, | |
| 226 | 추가: ..Limits::default() | |
| 227 | 추가: }, | |
| 228 | 추가: ) | |
| 229 | 추가: .unwrap(); | |
| 230 | 추가: expect_usage(&result, 65_537); | |
| 231 | 추가: sandbox.finish(); | |
| 232 | 추가: } | |
| 233 | 추가: | |
| 234 | 추가: #[test] | |
| 235 | 추가: fn one_less_io_budget_fails_last_eof_without_refund() { | |
| 236 | 추가: let sandbox = Sandbox::new(); | |
| 237 | 추가: let path = sandbox.file("input", &pattern(65_537)); | |
| 238 | 추가: let failure = get( | |
| 239 | 추가: &path, | |
| 240 | 추가: Limits { | |
| 241 | 추가: max_io_bytes: 131_075, | |
| 242 | 추가: ..Limits::default() | |
| 243 | 추가: }, | |
| 244 | 추가: ) | |
| 245 | 추가: .unwrap_err(); | |
| 246 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::IoBytes))); | |
| 247 | 추가: assert_eq!(failure.usage.read_calls, 5); | |
| 248 | 추가: assert_eq!(failure.usage.reserved_read_bytes, 131_075); | |
| 249 | 추가: assert_eq!(failure.usage.actual_read_bytes, 131_074); | |
| 250 | 추가: assert_eq!(failure.usage.compared_bytes, 65_537); | |
| 251 | 추가: sandbox.finish(); | |
| 252 | 추가: } | |
| 253 | 추가: | |
| 254 | 추가: #[test] | |
| 255 | 추가: fn one_less_call_budget_fails_last_eof() { | |
| 256 | 추가: let sandbox = Sandbox::new(); | |
| 257 | 추가: let path = sandbox.file("input", &pattern(65_537)); | |
| 258 | 추가: let failure = get( | |
| 259 | 추가: &path, | |
| 260 | 추가: Limits { | |
| 261 | 추가: max_read_calls: 5, | |
| 262 | 추가: ..Limits::default() | |
| 263 | 추가: }, | |
| 264 | 추가: ) | |
| 265 | 추가: .unwrap_err(); | |
| 266 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::ReadCalls))); | |
| 267 | 추가: assert_eq!(failure.usage.read_calls, 5); | |
| 268 | 추가: assert_eq!(failure.usage.reserved_read_bytes, 131_075); | |
| 269 | 추가: sandbox.finish(); | |
| 270 | 추가: } | |
| 271 | 추가: | |
| 272 | 추가: #[test] | |
| 273 | 추가: fn retry_usage_is_per_attempt_not_hidden_cumulative_state() { | |
| 274 | 추가: let sandbox = Sandbox::new(); | |
| 275 | 추가: let path = sandbox.file("input", b"x"); | |
| 276 | 추가: let failure = get( | |
| 277 | 추가: &path, | |
| 278 | 추가: Limits { | |
| 279 | 추가: max_read_calls: 1, | |
| 280 | 추가: ..Limits::default() | |
| 281 | 추가: }, | |
| 282 | 추가: ) | |
| 283 | 추가: .unwrap_err(); | |
| 284 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::ReadCalls))); | |
| 285 | 추가: assert_eq!(failure.usage.actual_read_bytes, 1); | |
| 286 | 추가: let result = get(&path, Limits::default()).unwrap(); | |
| 287 | 추가: expect_usage(&result, 1); | |
| 288 | 추가: sandbox.finish(); | |
| 289 | 추가: } |
| @@ -0,0 +1,226 @@ | ||
| 1 | 추가: { | |
| 2 | 추가: "schema": "zipelo.file-snapshot.regressions.v1", | |
| 3 | 추가: "source_head": "b7c3d5575943f8caab8bbdcf465c278c3e7059d1", | |
| 4 | 추가: "source_manifest_sha256": "668b1c3f140a033a6a0768b84ec52f111ee5fbfaf707632d2fc9a5a380758120", | |
| 5 | 추가: "branch": "fix/rust-file-snapshot-regressions", | |
| 6 | 추가: "scope": "Source-only public API regressions; Rust compile/discovery/execution not performed. No production changes, copies, include!, private access, worker or publication.", | |
| 7 | 추가: "declared_test_count": 72, | |
| 8 | 추가: "test_names": [ | |
| 9 | 추가: "boundaries::chunk", | |
| 10 | 추가: "boundaries::chunk_minus_one", | |
| 11 | 추가: "boundaries::chunk_plus_one", | |
| 12 | 추가: "boundaries::empty", | |
| 13 | 추가: "boundaries::empty_accepts_zero_byte_limit_with_exact_eof_budget", | |
| 14 | 추가: "boundaries::exact_io_and_call_budget_includes_both_eof_probes", | |
| 15 | 추가: "boundaries::invalid_bytes_cap", | |
| 16 | 추가: "boundaries::invalid_calls_cap", | |
| 17 | 추가: "boundaries::invalid_calls_zero", | |
| 18 | 추가: "boundaries::invalid_deadline_cap", | |
| 19 | 추가: "boundaries::invalid_deadline_zero", | |
| 20 | 추가: "boundaries::invalid_io_cap", | |
| 21 | 추가: "boundaries::maximum", | |
| 22 | 추가: "boundaries::maximum_minus_one", | |
| 23 | 추가: "boundaries::nonempty_rejects_zero_byte_limit", | |
| 24 | 추가: "boundaries::one", | |
| 25 | 추가: "boundaries::one_less_call_budget_fails_last_eof", | |
| 26 | 추가: "boundaries::one_less_io_budget_fails_last_eof_without_refund", | |
| 27 | 추가: "boundaries::retry_usage_is_per_attempt_not_hidden_cumulative_state", | |
| 28 | 추가: "boundaries::sha256_known_abc_and_debug_redaction", | |
| 29 | 추가: "boundaries::source_over_maximum_rejected_before_data_open", | |
| 30 | 추가: "boundaries::zero_io_budget_is_valid_but_cannot_probe_eof", | |
| 31 | 추가: "control::callback_error_precedes_expired_checkpoint_deadline", | |
| 32 | 추가: "control::callback_error_precedes_next_observed_source_change", | |
| 33 | 추가: "control::callback_panic_propagates_without_snapshot", | |
| 34 | 추가: "control::callback_preserves_non_send_error_identity", | |
| 35 | 추가: "control::cancel_after_first_chunk_preserves_accumulated_usage", | |
| 36 | 추가: "control::cancel_at_comparing", | |
| 37 | 추가: "control::cancel_at_copying", | |
| 38 | 추가: "control::cancel_at_finalizing", | |
| 39 | 추가: "control::cancel_at_opening", | |
| 40 | 추가: "control::cancel_at_pinned", | |
| 41 | 추가: "control::cancellation_precedes_expired_checkpoint_deadline", | |
| 42 | 추가: "control::cancellation_requested_after_return_does_not_change_owned_result", | |
| 43 | 추가: "control::checkpoint_order_offsets_and_usage_are_observable", | |
| 44 | 추가: "control::natural_elapsed_deadline_precedes_path_validation", | |
| 45 | 추가: "control::selected_public_types_have_send_bounds", | |
| 46 | 추가: "mutations::append_after_comparison_detected_by_second_eof_probe", | |
| 47 | 추가: "mutations::append_after_copy_detected_by_first_eof_probe", | |
| 48 | 추가: "mutations::append_after_pinning_detected_before_data_read", | |
| 49 | 추가: "mutations::finalizing_append_detected_by_final_metadata", | |
| 50 | 추가: "mutations::hard_link_added_at_finalizing_rejected", | |
| 51 | 추가: "mutations::positive_short_read_is_accumulated_before_later_eof", | |
| 52 | 추가: "mutations::replaced_leaf_never_captures_replacement_bytes", | |
| 53 | 추가: "mutations::replaced_parent_keeps_pinned_inode_not_new_path_contents", | |
| 54 | 추가: "mutations::returned_snapshot_owns_bytes_after_source_changes", | |
| 55 | 추가: "mutations::same_size_overwrite_before_comparison_returns_content_change", | |
| 56 | 추가: "mutations::truncate_after_pinning_detected_before_data_read", | |
| 57 | 추가: "mutations::truncate_before_comparison_returns_early_eof", | |
| 58 | 추가: "mutations::truncate_before_copy_returns_early_eof", | |
| 59 | 추가: "paths::ancestor_symlink_rejected", | |
| 60 | 추가: "paths::component_255_bytes_is_supported", | |
| 61 | 추가: "paths::component_over_255", | |
| 62 | 추가: "paths::dangling_symlink_preserves_eloop", | |
| 63 | 추가: "paths::directory_rejected_before_data_open", | |
| 64 | 추가: "paths::dot_component", | |
| 65 | 추가: "paths::empty_path", | |
| 66 | 추가: "paths::fifo_without_writer_rejected_before_data_open", | |
| 67 | 추가: "paths::leaf_symlink_rejected_without_reading_target", | |
| 68 | 추가: "paths::linux_backslash_and_colon_are_name_bytes", | |
| 69 | 추가: "paths::missing_path_preserves_enoent_and_stage", | |
| 70 | 추가: "paths::multiple_hard_links_rejected_and_contents_preserved", | |
| 71 | 추가: "paths::non_utf8_linux_name_is_supported", | |
| 72 | 추가: "paths::nul_byte", | |
| 73 | 추가: "paths::parent_component", | |
| 74 | 추가: "paths::path_over_4096", | |
| 75 | 추가: "paths::regular_parent_component_preserves_enotdir", | |
| 76 | 추가: "paths::relative_path", | |
| 77 | 추가: "paths::repeated_slash", | |
| 78 | 추가: "paths::root_only", | |
| 79 | 추가: "paths::trailing_slash", | |
| 80 | 추가: "paths::unix_socket_rejected_before_data_open" | |
| 81 | 추가: ], | |
| 82 | 추가: "evidence_classes": { | |
| 83 | 추가: "boundaries::chunk": "real-file-public-api", | |
| 84 | 추가: "boundaries::chunk_minus_one": "real-file-public-api", | |
| 85 | 추가: "boundaries::chunk_plus_one": "real-file-public-api", | |
| 86 | 추가: "boundaries::empty": "real-file-public-api", | |
| 87 | 추가: "boundaries::empty_accepts_zero_byte_limit_with_exact_eof_budget": "real-file-public-api", | |
| 88 | 추가: "boundaries::exact_io_and_call_budget_includes_both_eof_probes": "real-file-public-api", | |
| 89 | 추가: "boundaries::invalid_bytes_cap": "public-validation-no-file", | |
| 90 | 추가: "boundaries::invalid_calls_cap": "public-validation-no-file", | |
| 91 | 추가: "boundaries::invalid_calls_zero": "public-validation-no-file", | |
| 92 | 추가: "boundaries::invalid_deadline_cap": "public-validation-no-file", | |
| 93 | 추가: "boundaries::invalid_deadline_zero": "public-validation-no-file", | |
| 94 | 추가: "boundaries::invalid_io_cap": "public-validation-no-file", | |
| 95 | 추가: "boundaries::maximum": "real-file-public-api", | |
| 96 | 추가: "boundaries::maximum_minus_one": "real-file-public-api", | |
| 97 | 추가: "boundaries::nonempty_rejects_zero_byte_limit": "real-file-public-api", | |
| 98 | 추가: "boundaries::one": "real-file-public-api", | |
| 99 | 추가: "boundaries::one_less_call_budget_fails_last_eof": "real-file-public-api", | |
| 100 | 추가: "boundaries::one_less_io_budget_fails_last_eof_without_refund": "real-file-public-api", | |
| 101 | 추가: "boundaries::retry_usage_is_per_attempt_not_hidden_cumulative_state": "real-file-public-api", | |
| 102 | 추가: "boundaries::sha256_known_abc_and_debug_redaction": "real-file-public-api", | |
| 103 | 추가: "boundaries::source_over_maximum_rejected_before_data_open": "real-file-public-api", | |
| 104 | 추가: "boundaries::zero_io_budget_is_valid_but_cannot_probe_eof": "real-file-public-api", | |
| 105 | 추가: "control::callback_error_precedes_expired_checkpoint_deadline": "natural-elapsed-callback-no-file", | |
| 106 | 추가: "control::callback_error_precedes_next_observed_source_change": "real-file-callback-injection", | |
| 107 | 추가: "control::callback_panic_propagates_without_snapshot": "real-file-callback-injection", | |
| 108 | 추가: "control::callback_preserves_non_send_error_identity": "real-file-callback-injection", | |
| 109 | 추가: "control::cancel_after_first_chunk_preserves_accumulated_usage": "real-file-callback-injection", | |
| 110 | 추가: "control::cancel_at_comparing": "real-file-callback-injection", | |
| 111 | 추가: "control::cancel_at_copying": "real-file-callback-injection", | |
| 112 | 추가: "control::cancel_at_finalizing": "real-file-callback-injection", | |
| 113 | 추가: "control::cancel_at_opening": "real-file-callback-injection", | |
| 114 | 추가: "control::cancel_at_pinned": "real-file-callback-injection", | |
| 115 | 추가: "control::cancellation_precedes_expired_checkpoint_deadline": "natural-elapsed-callback-no-file", | |
| 116 | 추가: "control::cancellation_requested_after_return_does_not_change_owned_result": "real-file-callback-injection", | |
| 117 | 추가: "control::checkpoint_order_offsets_and_usage_are_observable": "real-file-callback-injection", | |
| 118 | 추가: "control::natural_elapsed_deadline_precedes_path_validation": "natural-elapsed-callback-no-file", | |
| 119 | 추가: "control::selected_public_types_have_send_bounds": "compile-bound-assertions", | |
| 120 | 추가: "mutations::append_after_comparison_detected_by_second_eof_probe": "real-file-checkpoint-mutation", | |
| 121 | 추가: "mutations::append_after_copy_detected_by_first_eof_probe": "real-file-checkpoint-mutation", | |
| 122 | 추가: "mutations::append_after_pinning_detected_before_data_read": "real-file-checkpoint-mutation", | |
| 123 | 추가: "mutations::finalizing_append_detected_by_final_metadata": "real-file-checkpoint-mutation", | |
| 124 | 추가: "mutations::hard_link_added_at_finalizing_rejected": "real-file-checkpoint-mutation", | |
| 125 | 추가: "mutations::positive_short_read_is_accumulated_before_later_eof": "real-file-checkpoint-mutation", | |
| 126 | 추가: "mutations::replaced_leaf_never_captures_replacement_bytes": "real-file-checkpoint-mutation", | |
| 127 | 추가: "mutations::replaced_parent_keeps_pinned_inode_not_new_path_contents": "real-file-checkpoint-mutation", | |
| 128 | 추가: "mutations::returned_snapshot_owns_bytes_after_source_changes": "real-file-checkpoint-mutation", | |
| 129 | 추가: "mutations::same_size_overwrite_before_comparison_returns_content_change": "real-file-checkpoint-mutation", | |
| 130 | 추가: "mutations::truncate_after_pinning_detected_before_data_read": "real-file-checkpoint-mutation", | |
| 131 | 추가: "mutations::truncate_before_comparison_returns_early_eof": "real-file-checkpoint-mutation", | |
| 132 | 추가: "mutations::truncate_before_copy_returns_early_eof": "real-file-checkpoint-mutation", | |
| 133 | 추가: "paths::ancestor_symlink_rejected": "real-file-public-api", | |
| 134 | 추가: "paths::component_255_bytes_is_supported": "real-file-public-api", | |
| 135 | 추가: "paths::component_over_255": "public-validation-no-file", | |
| 136 | 추가: "paths::dangling_symlink_preserves_eloop": "real-file-public-api", | |
| 137 | 추가: "paths::directory_rejected_before_data_open": "real-file-public-api", | |
| 138 | 추가: "paths::dot_component": "public-validation-no-file", | |
| 139 | 추가: "paths::empty_path": "public-validation-no-file", | |
| 140 | 추가: "paths::fifo_without_writer_rejected_before_data_open": "real-file-public-api", | |
| 141 | 추가: "paths::leaf_symlink_rejected_without_reading_target": "real-file-public-api", | |
| 142 | 추가: "paths::linux_backslash_and_colon_are_name_bytes": "real-file-public-api", | |
| 143 | 추가: "paths::missing_path_preserves_enoent_and_stage": "real-file-public-api", | |
| 144 | 추가: "paths::multiple_hard_links_rejected_and_contents_preserved": "real-file-public-api", | |
| 145 | 추가: "paths::non_utf8_linux_name_is_supported": "real-file-public-api", | |
| 146 | 추가: "paths::nul_byte": "public-validation-no-file", | |
| 147 | 추가: "paths::parent_component": "public-validation-no-file", | |
| 148 | 추가: "paths::path_over_4096": "public-validation-no-file", | |
| 149 | 추가: "paths::regular_parent_component_preserves_enotdir": "real-file-public-api", | |
| 150 | 추가: "paths::relative_path": "public-validation-no-file", | |
| 151 | 추가: "paths::repeated_slash": "public-validation-no-file", | |
| 152 | 추가: "paths::root_only": "public-validation-no-file", | |
| 153 | 추가: "paths::trailing_slash": "public-validation-no-file", | |
| 154 | 추가: "paths::unix_socket_rejected_before_data_open": "real-file-public-api" | |
| 155 | 추가: }, | |
| 156 | 추가: "fixture_provenance": { | |
| 157 | 추가: "input": "Only source-defined synthetic bytes: pattern(i)=(i*37+11)%251, fixed ASCII literals and generated boundary lengths. No archives, user files or external fixtures.", | |
| 158 | 추가: "digest": "SHA256 known-answer for ASCII abc: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad. Rust expected bytes are independent of the production digest implementation.", | |
| 159 | 추가: "filesystem": "Future runs create mode-0700 runs/case-PID-counter exclusively below this test directory. File helpers create_new. Mutation cases intentionally alter only their own synthetic input. Root identity checked before cleanup; no Drop cleanup on failed assertions, so evidence remains. No hostile concurrent actor or same-UID deletion safety claim.", | |
| 160 | 추가: "special_files": "FIFO via existing libc::mkfifo, local Unix socket inode without accepting connections, directory, hard links, and symlinks inside each owned sandbox. No device node creation, system special files or mounts.", | |
| 161 | 추가: "boundary_lengths": [ | |
| 162 | 추가: 0, | |
| 163 | 추가: 1, | |
| 164 | 추가: 65535, | |
| 165 | 추가: 65536, | |
| 166 | 추가: 65537, | |
| 167 | 추가: 16777215, | |
| 168 | 추가: 16777216, | |
| 169 | 추가: 16777217 | |
| 170 | 추가: ] | |
| 171 | 추가: }, | |
| 172 | 추가: "contracts": { | |
| 173 | 추가: "acquisition": "Frozen source remains unchanged. All Rust tests use the actual path dependency and public API. Callback mutations occur synchronously at real capture checkpoints, not timing races.", | |
| 174 | 추가: "success": "Normal full-read accounting is 2*N+2 reserved, 2*N actual, N compared and 2*ceil(N/65536)+2 calls. EOF and failed attempt reservations are not refunded.", | |
| 175 | 추가: "short_read": "Truncating at the first Copying checkpoint forces a positive one-byte read followed by EOF. The offset-1 checkpoint proves accumulation; the final expected outcome is Changed(Length), not successful short-read completion.", | |
| 176 | 추가: "replacement": "Parent rename/replacement retains the old regular-file inode without re-resolving the caller path. Leaf replacement unlinks the old inode and therefore expects Unsupported(MultipleLinks) from the nlink!=1 guard. No original-path persistence guarantee.", | |
| 177 | 추가: "cancellation": "Opening/Pinned/Copying/Comparing/Finalizing cancellation and typed callback error preserve usage. Callback errors win over next source observation and expired checkpoint deadline. Finalizing-to-return race remains uncovered.", | |
| 178 | 추가: "timing": "Three deadline-priority cases use natural elapsed time after a 10 ms callback sleep against a 1 ms budget. They are not injected clocks, hard deadlines, scheduler/latency guarantees or worker cleanup proof.", | |
| 179 | 추가: "panic": "One intentional callback panic is caught; source content is checked. This is not fd-close or OS cleanup evidence.", | |
| 180 | 추가: "send": "One Rust test contains Send bounds for selected types; non-Send Rc callback E is separately preserved. No compile result until approved no-run. No universal 'static or Send E requirement is claimed.", | |
| 181 | 추가: "privacy": "FileSnapshot Debug is checked against bytes/path/digest/identity exposure. Other generic callback/error Debug output is not covered.", | |
| 182 | 추가: "cleanup": "Explicit sandbox finish on success; any panic/error/timeout leaves the case directory and stops later cases. No cleanup success inferred from Drop.", | |
| 183 | 추가: "old_results": "Existing 16 classification failures and seven unverified cases remain unchanged and are not counted in these 72 declarations." | |
| 184 | 추가: }, | |
| 185 | 추가: "unverified": [ | |
| 186 | 추가: "Successful positive-short-read sequence, read EINTR/EIO/permission errno, allocator failure and arbitrary syscall fault injection: no public injection boundary; no production hook or private include added.", | |
| 187 | 추가: "Device and block nodes, procfs substitution, kernel primitive absence, privileged mounts and malicious same-process fd reuse.", | |
| 188 | 추가: "Changed(Identity) from a correctly pinned FD, deterministic standalone Changed(Metadata), full ABA/same-inode mutation exclusion, atomic point-in-time copy.", | |
| 189 | 추가: "Cancellation after final callback before return, final-metadata native failure vs deadline precedence.", | |
| 190 | 추가: "Opaque-constructor compile-fail checks, non-Linux runtime/Unsupported branch, Windows/VM, strict syscall timeout, fd leak/cleanup proof.", | |
| 191 | 추가: "OS worker launch/identity/EOF/reap, publication/commit/durability; execveat EACCES and held probes stay deferred." | |
| 192 | 추가: ], | |
| 193 | 추가: "future_execution": { | |
| 194 | 추가: "gate": "Separate fixed-head review required before any Rust compile/no-run/discovery/runtime or fixture syscall execution.", | |
| 195 | 추가: "order": "Verify source+test hashes -> locked/offline no-run -> list --format terse -> validate every nonempty line and exact unique name set -> execute each exact name once, --test-threads=1 --nocapture.", | |
| 196 | 추가: "test_target": "snapshot_public_api", | |
| 197 | 추가: "per_case_filtered": 71, | |
| 198 | 추가: "cases_serial": true, | |
| 199 | 추가: "max_parallel_publishers": 0, | |
| 200 | 추가: "compile_timeout_seconds": 120, | |
| 201 | 추가: "per_case_timeout_seconds": 30, | |
| 202 | 추가: "logs_per_command_bytes": 8388608, | |
| 203 | 추가: "max_case_data_bytes": 134217728, | |
| 204 | 추가: "on_failure": "Stop at first compile/discovery/test/nonzero/unknown result; preserve logs and residual paths. No source/expectation edits or repeats. Deadline expiry requests termination only of the harness-owned test child; failure to reap is a separate blocked result.", | |
| 205 | 추가: "limit_caveat": "Parent timeout is observation/control, not a guarantee of interrupting uninterruptible kernel I/O. No worker isolation claim.", | |
| 206 | 추가: "records": "Exact argv/cwd/env allowlist, exit/status, raw stdout/stderr SHA256, binary SHA256, exact discovered/executed/pass/fail/ignored/filtered sets, source/test hashes before/after. Runs and validation output remain local and excluded from PR.", | |
| 207 | 추가: "commands": [ | |
| 208 | 추가: "CARGO_TARGET_DIR=tests/rust-file-snapshot/target cargo test --manifest-path tests/rust-file-snapshot/Cargo.toml --locked --offline --test snapshot_public_api --no-run --message-format=json", | |
| 209 | 추가: "<fixed-binary> --list --format terse", | |
| 210 | 추가: "<fixed-binary> --exact <contract-name> --test-threads=1 --nocapture" | |
| 211 | 추가: ], | |
| 212 | 추가: "toolchain": "Existing 1.99.1-x86_64-unknown-linux-gnu explicitly selected; default stable lacks rustfmt. No toolchain installation or shared override.", | |
| 213 | 추가: "sandbox_precondition": "Approved runner creates tests/rust-file-snapshot/runs with mode 0700 before tests, verifies no symlink and expected owner, and refuses leftover case directories. No sandbox or synthetic input has been created at source-only stage." | |
| 214 | 추가: }, | |
| 215 | 추가: "static_validation": { | |
| 216 | 추가: "allowed": [ | |
| 217 | 추가: "rustfmt --check", | |
| 218 | 추가: "normal Python static checks and checker helper tests", | |
| 219 | 추가: "cargo generate-lockfile --offline", | |
| 220 | 추가: "cargo metadata --locked --offline" | |
| 221 | 추가: ], | |
| 222 | 추가: "python_guard": "Reject -O/PYTHONOPTIMIZE before argument parsing and file reads.", | |
| 223 | 추가: "manifest": "SHA256SUMS enumerates every deliverable except itself; source-pins.json independently records all nine fixed production blobs/hashes.", | |
| 224 | 추가: "deps": "Only production path dependency plus its existing libc version/features; no new registry package or feature. Cargo.lock must equal production packages plus test root." | |
| 225 | 추가: } | |
| 226 | 추가: } |
| @@ -0,0 +1,288 @@ | ||
| 1 | 추가: use crate::support::*; | |
| 2 | 추가: use snapshot::{ | |
| 3 | 추가: Checkpoint, Error, Failure, FileSnapshot, Identity, LimitKind, Limits, Request, Stage, Stop, | |
| 4 | 추가: Usage, capture, | |
| 5 | 추가: }; | |
| 6 | 추가: use std::{ | |
| 7 | 추가: cell::Cell, | |
| 8 | 추가: fs, | |
| 9 | 추가: panic::{AssertUnwindSafe, catch_unwind}, | |
| 10 | 추가: path::Path, | |
| 11 | 추가: rc::Rc, | |
| 12 | 추가: time::Duration, | |
| 13 | 추가: }; | |
| 14 | 추가: | |
| 15 | 추가: fn cancel(stage: Stage, reads: u64, actual: u64) { | |
| 16 | 추가: let sandbox = Sandbox::new(); | |
| 17 | 추가: let path = sandbox.file("input", b"abc"); | |
| 18 | 추가: let mut stopped = false; | |
| 19 | 추가: let failure = capture( | |
| 20 | 추가: Request { | |
| 21 | 추가: path: &path, | |
| 22 | 추가: limits: Limits::default(), | |
| 23 | 추가: }, | |
| 24 | 추가: |point| { | |
| 25 | 추가: if point.stage == stage { | |
| 26 | 추가: stopped = true; | |
| 27 | 추가: Err(Stop::<()>::Cancelled) | |
| 28 | 추가: } else { | |
| 29 | 추가: Ok(()) | |
| 30 | 추가: } | |
| 31 | 추가: }, | |
| 32 | 추가: ) | |
| 33 | 추가: .unwrap_err(); | |
| 34 | 추가: assert!(stopped); | |
| 35 | 추가: assert!(matches!(failure.cause, Error::Cancelled)); | |
| 36 | 추가: assert_eq!(failure.usage.read_calls, reads); | |
| 37 | 추가: assert_eq!(failure.usage.actual_read_bytes, actual); | |
| 38 | 추가: assert_eq!(fs::read(&path).unwrap(), b"abc"); | |
| 39 | 추가: sandbox.finish(); | |
| 40 | 추가: } | |
| 41 | 추가: | |
| 42 | 추가: #[test] | |
| 43 | 추가: fn cancel_at_opening() { | |
| 44 | 추가: cancel(Stage::Opening, 0, 0); | |
| 45 | 추가: } | |
| 46 | 추가: | |
| 47 | 추가: #[test] | |
| 48 | 추가: fn cancel_at_pinned() { | |
| 49 | 추가: cancel(Stage::Pinned, 0, 0); | |
| 50 | 추가: } | |
| 51 | 추가: | |
| 52 | 추가: #[test] | |
| 53 | 추가: fn cancel_at_copying() { | |
| 54 | 추가: cancel(Stage::Copying, 0, 0); | |
| 55 | 추가: } | |
| 56 | 추가: | |
| 57 | 추가: #[test] | |
| 58 | 추가: fn cancel_at_comparing() { | |
| 59 | 추가: cancel(Stage::Comparing, 2, 3); | |
| 60 | 추가: } | |
| 61 | 추가: | |
| 62 | 추가: #[test] | |
| 63 | 추가: fn cancel_at_finalizing() { | |
| 64 | 추가: cancel(Stage::Finalizing, 4, 6); | |
| 65 | 추가: } | |
| 66 | 추가: | |
| 67 | 추가: #[test] | |
| 68 | 추가: fn cancel_after_first_chunk_preserves_accumulated_usage() { | |
| 69 | 추가: let sandbox = Sandbox::new(); | |
| 70 | 추가: let path = sandbox.file("input", &pattern(65_537)); | |
| 71 | 추가: let failure = capture( | |
| 72 | 추가: Request { | |
| 73 | 추가: path: &path, | |
| 74 | 추가: limits: Limits::default(), | |
| 75 | 추가: }, | |
| 76 | 추가: |point| { | |
| 77 | 추가: if point.stage == Stage::Copying && point.offset == 65_536 { | |
| 78 | 추가: Err(Stop::<()>::Cancelled) | |
| 79 | 추가: } else { | |
| 80 | 추가: Ok(()) | |
| 81 | 추가: } | |
| 82 | 추가: }, | |
| 83 | 추가: ) | |
| 84 | 추가: .unwrap_err(); | |
| 85 | 추가: assert!(matches!(failure.cause, Error::Cancelled)); | |
| 86 | 추가: assert_eq!(failure.usage.read_calls, 1); | |
| 87 | 추가: assert_eq!(failure.usage.actual_read_bytes, 65_536); | |
| 88 | 추가: assert_eq!(failure.usage.reserved_read_bytes, 65_536); | |
| 89 | 추가: sandbox.finish(); | |
| 90 | 추가: } | |
| 91 | 추가: | |
| 92 | 추가: #[test] | |
| 93 | 추가: fn callback_preserves_non_send_error_identity() { | |
| 94 | 추가: let sandbox = Sandbox::new(); | |
| 95 | 추가: let path = sandbox.file("input", b"abc"); | |
| 96 | 추가: let marker = Rc::new(String::from("typed")); | |
| 97 | 추가: let failure = capture( | |
| 98 | 추가: Request { | |
| 99 | 추가: path: &path, | |
| 100 | 추가: limits: Limits::default(), | |
| 101 | 추가: }, | |
| 102 | 추가: |point| { | |
| 103 | 추가: if point.stage == Stage::Comparing { | |
| 104 | 추가: Err(Stop::Callback(marker.clone())) | |
| 105 | 추가: } else { | |
| 106 | 추가: Ok(()) | |
| 107 | 추가: } | |
| 108 | 추가: }, | |
| 109 | 추가: ) | |
| 110 | 추가: .unwrap_err(); | |
| 111 | 추가: match failure.cause { | |
| 112 | 추가: Error::Callback(value) => assert!(Rc::ptr_eq(&value, &marker)), | |
| 113 | 추가: other => panic!("unexpected: {other:?}"), | |
| 114 | 추가: } | |
| 115 | 추가: assert_eq!(failure.usage.actual_read_bytes, 3); | |
| 116 | 추가: sandbox.finish(); | |
| 117 | 추가: } | |
| 118 | 추가: | |
| 119 | 추가: #[test] | |
| 120 | 추가: fn callback_error_precedes_next_observed_source_change() { | |
| 121 | 추가: let sandbox = Sandbox::new(); | |
| 122 | 추가: let path = sandbox.file("input", b"abc"); | |
| 123 | 추가: let failure = capture( | |
| 124 | 추가: Request { | |
| 125 | 추가: path: &path, | |
| 126 | 추가: limits: Limits::default(), | |
| 127 | 추가: }, | |
| 128 | 추가: |point| { | |
| 129 | 추가: if point.stage == Stage::Comparing { | |
| 130 | 추가: fs::write(&path, b"xyz").unwrap(); | |
| 131 | 추가: Err(Stop::Callback(73_u16)) | |
| 132 | 추가: } else { | |
| 133 | 추가: Ok(()) | |
| 134 | 추가: } | |
| 135 | 추가: }, | |
| 136 | 추가: ) | |
| 137 | 추가: .unwrap_err(); | |
| 138 | 추가: assert!(matches!(failure.cause, Error::Callback(73))); | |
| 139 | 추가: assert_eq!(failure.usage.actual_read_bytes, 3); | |
| 140 | 추가: assert_eq!(failure.usage.compared_bytes, 0); | |
| 141 | 추가: sandbox.finish(); | |
| 142 | 추가: } | |
| 143 | 추가: | |
| 144 | 추가: fn expired(stop: Option<Stop<u16>>) -> Failure<u16> { | |
| 145 | 추가: let mut stop = Some(stop); | |
| 146 | 추가: capture( | |
| 147 | 추가: Request { | |
| 148 | 추가: path: Path::new("invalid"), | |
| 149 | 추가: limits: Limits { | |
| 150 | 추가: max_duration: Duration::from_millis(1), | |
| 151 | 추가: ..Limits::default() | |
| 152 | 추가: }, | |
| 153 | 추가: }, | |
| 154 | 추가: |_| { | |
| 155 | 추가: std::thread::sleep(Duration::from_millis(10)); | |
| 156 | 추가: match stop.take().unwrap() { | |
| 157 | 추가: Some(value) => Err(value), | |
| 158 | 추가: None => Ok(()), | |
| 159 | 추가: } | |
| 160 | 추가: }, | |
| 161 | 추가: ) | |
| 162 | 추가: .unwrap_err() | |
| 163 | 추가: } | |
| 164 | 추가: | |
| 165 | 추가: #[test] | |
| 166 | 추가: fn natural_elapsed_deadline_precedes_path_validation() { | |
| 167 | 추가: let failure = expired(None); | |
| 168 | 추가: assert!(matches!(failure.cause, Error::Limit(LimitKind::Deadline))); | |
| 169 | 추가: assert_eq!(failure.usage, Usage::default()); | |
| 170 | 추가: } | |
| 171 | 추가: | |
| 172 | 추가: #[test] | |
| 173 | 추가: fn cancellation_precedes_expired_checkpoint_deadline() { | |
| 174 | 추가: let failure = expired(Some(Stop::Cancelled)); | |
| 175 | 추가: assert!(matches!(failure.cause, Error::Cancelled)); | |
| 176 | 추가: assert_eq!(failure.usage, Usage::default()); | |
| 177 | 추가: } | |
| 178 | 추가: | |
| 179 | 추가: #[test] | |
| 180 | 추가: fn callback_error_precedes_expired_checkpoint_deadline() { | |
| 181 | 추가: let failure = expired(Some(Stop::Callback(91))); | |
| 182 | 추가: assert!(matches!(failure.cause, Error::Callback(91))); | |
| 183 | 추가: assert_eq!(failure.usage, Usage::default()); | |
| 184 | 추가: } | |
| 185 | 추가: | |
| 186 | 추가: #[test] | |
| 187 | 추가: fn checkpoint_order_offsets_and_usage_are_observable() { | |
| 188 | 추가: let sandbox = Sandbox::new(); | |
| 189 | 추가: let path = sandbox.file("input", b"abc"); | |
| 190 | 추가: let mut points: Vec<Checkpoint> = Vec::new(); | |
| 191 | 추가: let result = capture( | |
| 192 | 추가: Request { | |
| 193 | 추가: path: &path, | |
| 194 | 추가: limits: Limits::default(), | |
| 195 | 추가: }, | |
| 196 | 추가: |point| { | |
| 197 | 추가: points.push(point); | |
| 198 | 추가: Ok::<_, Stop<()>>(()) | |
| 199 | 추가: }, | |
| 200 | 추가: ) | |
| 201 | 추가: .unwrap(); | |
| 202 | 추가: assert_eq!( | |
| 203 | 추가: points | |
| 204 | 추가: .iter() | |
| 205 | 추가: .map(|p| (p.stage, p.offset)) | |
| 206 | 추가: .collect::<Vec<_>>(), | |
| 207 | 추가: vec![ | |
| 208 | 추가: (Stage::Opening, 0), | |
| 209 | 추가: (Stage::Pinned, 0), | |
| 210 | 추가: (Stage::Copying, 0), | |
| 211 | 추가: (Stage::Copying, 0), | |
| 212 | 추가: (Stage::Copying, 3), | |
| 213 | 추가: (Stage::Comparing, 0), | |
| 214 | 추가: (Stage::Comparing, 3), | |
| 215 | 추가: (Stage::Finalizing, 3), | |
| 216 | 추가: ] | |
| 217 | 추가: ); | |
| 218 | 추가: assert_eq!(points[0].length, None); | |
| 219 | 추가: assert!(points[1..].iter().all(|p| p.length == Some(3))); | |
| 220 | 추가: for pair in points.windows(2) { | |
| 221 | 추가: assert!(pair[0].usage.open_calls <= pair[1].usage.open_calls); | |
| 222 | 추가: assert!(pair[0].usage.metadata_calls <= pair[1].usage.metadata_calls); | |
| 223 | 추가: assert!(pair[0].usage.read_calls <= pair[1].usage.read_calls); | |
| 224 | 추가: assert!(pair[0].usage.reserved_read_bytes <= pair[1].usage.reserved_read_bytes); | |
| 225 | 추가: assert!(pair[0].usage.actual_read_bytes <= pair[1].usage.actual_read_bytes); | |
| 226 | 추가: assert!(pair[0].usage.compared_bytes <= pair[1].usage.compared_bytes); | |
| 227 | 추가: } | |
| 228 | 추가: expect_usage(&result, 3); | |
| 229 | 추가: sandbox.finish(); | |
| 230 | 추가: } | |
| 231 | 추가: | |
| 232 | 추가: #[test] | |
| 233 | 추가: fn callback_panic_propagates_without_snapshot() { | |
| 234 | 추가: let sandbox = Sandbox::new(); | |
| 235 | 추가: let path = sandbox.file("input", b"abc"); | |
| 236 | 추가: let result = catch_unwind(AssertUnwindSafe(|| { | |
| 237 | 추가: let _: Result<FileSnapshot, Failure<()>> = capture( | |
| 238 | 추가: Request { | |
| 239 | 추가: path: &path, | |
| 240 | 추가: limits: Limits::default(), | |
| 241 | 추가: }, | |
| 242 | 추가: |point| { | |
| 243 | 추가: if point.stage == Stage::Copying { | |
| 244 | 추가: panic!("intentional-checkpoint-panic"); | |
| 245 | 추가: } | |
| 246 | 추가: Ok(()) | |
| 247 | 추가: }, | |
| 248 | 추가: ); | |
| 249 | 추가: })); | |
| 250 | 추가: assert!(result.is_err()); | |
| 251 | 추가: assert_eq!(fs::read(&path).unwrap(), b"abc"); | |
| 252 | 추가: sandbox.finish(); | |
| 253 | 추가: } | |
| 254 | 추가: | |
| 255 | 추가: #[test] | |
| 256 | 추가: fn cancellation_requested_after_return_does_not_change_owned_result() { | |
| 257 | 추가: let sandbox = Sandbox::new(); | |
| 258 | 추가: let path = sandbox.file("input", b"abc"); | |
| 259 | 추가: let requested = Cell::new(false); | |
| 260 | 추가: let result = capture( | |
| 261 | 추가: Request { | |
| 262 | 추가: path: &path, | |
| 263 | 추가: limits: Limits::default(), | |
| 264 | 추가: }, | |
| 265 | 추가: |_| { | |
| 266 | 추가: if requested.get() { | |
| 267 | 추가: Err(Stop::<()>::Cancelled) | |
| 268 | 추가: } else { | |
| 269 | 추가: Ok(()) | |
| 270 | 추가: } | |
| 271 | 추가: }, | |
| 272 | 추가: ) | |
| 273 | 추가: .unwrap(); | |
| 274 | 추가: requested.set(true); | |
| 275 | 추가: assert_eq!(result.bytes(), b"abc"); | |
| 276 | 추가: expect_usage(&result, 3); | |
| 277 | 추가: sandbox.finish(); | |
| 278 | 추가: } | |
| 279 | 추가: | |
| 280 | 추가: #[test] | |
| 281 | 추가: fn selected_public_types_have_send_bounds() { | |
| 282 | 추가: fn send<T: Send>() {} | |
| 283 | 추가: send::<FileSnapshot>(); | |
| 284 | 추가: send::<Identity>(); | |
| 285 | 추가: send::<Request<'static>>(); | |
| 286 | 추가: send::<Failure<String>>(); | |
| 287 | 추가: send::<Stop<String>>(); | |
| 288 | 추가: } |
| @@ -0,0 +1,7 @@ | ||
| 1 | 추가: #![cfg(target_os = "linux")] | |
| 2 | 추가: | |
| 3 | 추가: mod boundaries; | |
| 4 | 추가: mod control; | |
| 5 | 추가: mod mutations; | |
| 6 | 추가: mod paths; | |
| 7 | 추가: mod support; |
| @@ -0,0 +1,248 @@ | ||
| 1 | 추가: use crate::support::*; | |
| 2 | 추가: use snapshot::{Changed, Error, Limits, Request, Stage, Stop, Unsupported, capture}; | |
| 3 | 추가: use std::{ | |
| 4 | 추가: fs::{self, OpenOptions}, | |
| 5 | 추가: io::Write, | |
| 6 | 추가: os::unix::fs::MetadataExt, | |
| 7 | 추가: }; | |
| 8 | 추가: | |
| 9 | 추가: fn alter( | |
| 10 | 추가: stage: Stage, | |
| 11 | 추가: offset: u64, | |
| 12 | 추가: action: impl FnOnce(&std::path::Path), | |
| 13 | 추가: ) -> snapshot::Failure<()> { | |
| 14 | 추가: let sandbox = Sandbox::new(); | |
| 15 | 추가: let path = sandbox.file("input", &pattern(32)); | |
| 16 | 추가: let mut action = Some(action); | |
| 17 | 추가: let result = capture( | |
| 18 | 추가: Request { | |
| 19 | 추가: path: &path, | |
| 20 | 추가: limits: Limits::default(), | |
| 21 | 추가: }, | |
| 22 | 추가: |point| { | |
| 23 | 추가: if point.stage == stage && point.offset == offset { | |
| 24 | 추가: if let Some(action) = action.take() { | |
| 25 | 추가: action(&path); | |
| 26 | 추가: } | |
| 27 | 추가: } | |
| 28 | 추가: Ok::<_, Stop<()>>(()) | |
| 29 | 추가: }, | |
| 30 | 추가: ) | |
| 31 | 추가: .unwrap_err(); | |
| 32 | 추가: assert!(action.is_none()); | |
| 33 | 추가: sandbox.finish(); | |
| 34 | 추가: result | |
| 35 | 추가: } | |
| 36 | 추가: | |
| 37 | 추가: fn append(path: &std::path::Path) { | |
| 38 | 추가: OpenOptions::new() | |
| 39 | 추가: .append(true) | |
| 40 | 추가: .open(path) | |
| 41 | 추가: .unwrap() | |
| 42 | 추가: .write_all(b"x") | |
| 43 | 추가: .unwrap(); | |
| 44 | 추가: } | |
| 45 | 추가: | |
| 46 | 추가: fn truncate(path: &std::path::Path) { | |
| 47 | 추가: OpenOptions::new() | |
| 48 | 추가: .write(true) | |
| 49 | 추가: .open(path) | |
| 50 | 추가: .unwrap() | |
| 51 | 추가: .set_len(0) | |
| 52 | 추가: .unwrap(); | |
| 53 | 추가: } | |
| 54 | 추가: | |
| 55 | 추가: #[test] | |
| 56 | 추가: fn append_after_pinning_detected_before_data_read() { | |
| 57 | 추가: let usage = changed(alter(Stage::Pinned, 0, append), Changed::Length); | |
| 58 | 추가: assert_eq!(usage.read_calls, 0); | |
| 59 | 추가: } | |
| 60 | 추가: | |
| 61 | 추가: #[test] | |
| 62 | 추가: fn truncate_after_pinning_detected_before_data_read() { | |
| 63 | 추가: let usage = changed(alter(Stage::Pinned, 0, truncate), Changed::Length); | |
| 64 | 추가: assert_eq!(usage.read_calls, 0); | |
| 65 | 추가: } | |
| 66 | 추가: | |
| 67 | 추가: #[test] | |
| 68 | 추가: fn append_after_copy_detected_by_first_eof_probe() { | |
| 69 | 추가: let usage = changed(alter(Stage::Copying, 32, append), Changed::Length); | |
| 70 | 추가: assert_eq!(usage.read_calls, 2); | |
| 71 | 추가: assert_eq!(usage.actual_read_bytes, 33); | |
| 72 | 추가: assert_eq!(usage.compared_bytes, 0); | |
| 73 | 추가: } | |
| 74 | 추가: | |
| 75 | 추가: #[test] | |
| 76 | 추가: fn truncate_before_copy_returns_early_eof() { | |
| 77 | 추가: let usage = changed(alter(Stage::Copying, 0, truncate), Changed::Length); | |
| 78 | 추가: assert_eq!(usage.read_calls, 1); | |
| 79 | 추가: assert_eq!(usage.actual_read_bytes, 0); | |
| 80 | 추가: assert_eq!(usage.reserved_read_bytes, 32); | |
| 81 | 추가: } | |
| 82 | 추가: | |
| 83 | 추가: #[test] | |
| 84 | 추가: fn positive_short_read_is_accumulated_before_later_eof() { | |
| 85 | 추가: let sandbox = Sandbox::new(); | |
| 86 | 추가: let path = sandbox.file("input", &pattern(65_537)); | |
| 87 | 추가: let mut altered = false; | |
| 88 | 추가: let mut saw_short = false; | |
| 89 | 추가: let failure = capture( | |
| 90 | 추가: Request { | |
| 91 | 추가: path: &path, | |
| 92 | 추가: limits: Limits::default(), | |
| 93 | 추가: }, | |
| 94 | 추가: |point| { | |
| 95 | 추가: if point.stage == Stage::Copying && !altered { | |
| 96 | 추가: OpenOptions::new() | |
| 97 | 추가: .write(true) | |
| 98 | 추가: .open(&path) | |
| 99 | 추가: .unwrap() | |
| 100 | 추가: .set_len(1) | |
| 101 | 추가: .unwrap(); | |
| 102 | 추가: altered = true; | |
| 103 | 추가: } | |
| 104 | 추가: if point.stage == Stage::Copying && point.offset == 1 { | |
| 105 | 추가: assert_eq!(point.usage.actual_read_bytes, 1); | |
| 106 | 추가: saw_short = true; | |
| 107 | 추가: } | |
| 108 | 추가: Ok::<_, Stop<()>>(()) | |
| 109 | 추가: }, | |
| 110 | 추가: ) | |
| 111 | 추가: .unwrap_err(); | |
| 112 | 추가: let usage = changed(failure, Changed::Length); | |
| 113 | 추가: assert!(altered && saw_short); | |
| 114 | 추가: assert_eq!(usage.read_calls, 2); | |
| 115 | 추가: assert_eq!(usage.reserved_read_bytes, 131_072); | |
| 116 | 추가: assert_eq!(usage.actual_read_bytes, 1); | |
| 117 | 추가: sandbox.finish(); | |
| 118 | 추가: } | |
| 119 | 추가: | |
| 120 | 추가: #[test] | |
| 121 | 추가: fn same_size_overwrite_before_comparison_returns_content_change() { | |
| 122 | 추가: let usage = changed( | |
| 123 | 추가: alter(Stage::Comparing, 0, |path| { | |
| 124 | 추가: fs::write(path, vec![99; 32]).unwrap() | |
| 125 | 추가: }), | |
| 126 | 추가: Changed::Contents, | |
| 127 | 추가: ); | |
| 128 | 추가: assert_eq!(usage.actual_read_bytes, 64); | |
| 129 | 추가: assert_eq!(usage.compared_bytes, 32); | |
| 130 | 추가: } | |
| 131 | 추가: | |
| 132 | 추가: #[test] | |
| 133 | 추가: fn truncate_before_comparison_returns_early_eof() { | |
| 134 | 추가: let usage = changed(alter(Stage::Comparing, 0, truncate), Changed::Length); | |
| 135 | 추가: assert_eq!(usage.actual_read_bytes, 32); | |
| 136 | 추가: assert_eq!(usage.compared_bytes, 0); | |
| 137 | 추가: assert_eq!(usage.read_calls, 3); | |
| 138 | 추가: } | |
| 139 | 추가: | |
| 140 | 추가: #[test] | |
| 141 | 추가: fn append_after_comparison_detected_by_second_eof_probe() { | |
| 142 | 추가: let usage = changed(alter(Stage::Comparing, 32, append), Changed::Length); | |
| 143 | 추가: assert_eq!(usage.actual_read_bytes, 65); | |
| 144 | 추가: assert_eq!(usage.compared_bytes, 32); | |
| 145 | 추가: assert_eq!(usage.read_calls, 4); | |
| 146 | 추가: } | |
| 147 | 추가: | |
| 148 | 추가: #[test] | |
| 149 | 추가: fn finalizing_append_detected_by_final_metadata() { | |
| 150 | 추가: let usage = changed(alter(Stage::Finalizing, 32, append), Changed::Length); | |
| 151 | 추가: assert_eq!(usage.actual_read_bytes, 64); | |
| 152 | 추가: assert_eq!(usage.metadata_calls, 5); | |
| 153 | 추가: } | |
| 154 | 추가: | |
| 155 | 추가: #[test] | |
| 156 | 추가: fn hard_link_added_at_finalizing_rejected() { | |
| 157 | 추가: let sandbox = Sandbox::new(); | |
| 158 | 추가: let path = sandbox.file("input", b"abc"); | |
| 159 | 추가: let failure = capture( | |
| 160 | 추가: Request { | |
| 161 | 추가: path: &path, | |
| 162 | 추가: limits: Limits::default(), | |
| 163 | 추가: }, | |
| 164 | 추가: |point| { | |
| 165 | 추가: if point.stage == Stage::Finalizing { | |
| 166 | 추가: fs::hard_link(&path, sandbox.path("alias")).unwrap(); | |
| 167 | 추가: } | |
| 168 | 추가: Ok::<_, Stop<()>>(()) | |
| 169 | 추가: }, | |
| 170 | 추가: ) | |
| 171 | 추가: .unwrap_err(); | |
| 172 | 추가: assert!(matches!( | |
| 173 | 추가: failure.cause, | |
| 174 | 추가: Error::Unsupported(Unsupported::MultipleLinks) | |
| 175 | 추가: )); | |
| 176 | 추가: assert_eq!(failure.usage.actual_read_bytes, 6); | |
| 177 | 추가: sandbox.finish(); | |
| 178 | 추가: } | |
| 179 | 추가: | |
| 180 | 추가: #[test] | |
| 181 | 추가: fn replaced_leaf_never_captures_replacement_bytes() { | |
| 182 | 추가: let sandbox = Sandbox::new(); | |
| 183 | 추가: let path = sandbox.file("input", b"old"); | |
| 184 | 추가: let replacement = sandbox.file("replacement", b"new"); | |
| 185 | 추가: let failure = capture( | |
| 186 | 추가: Request { | |
| 187 | 추가: path: &path, | |
| 188 | 추가: limits: Limits::default(), | |
| 189 | 추가: }, | |
| 190 | 추가: |point| { | |
| 191 | 추가: if point.stage == Stage::Pinned { | |
| 192 | 추가: fs::rename(&replacement, &path).unwrap(); | |
| 193 | 추가: } | |
| 194 | 추가: Ok::<_, Stop<()>>(()) | |
| 195 | 추가: }, | |
| 196 | 추가: ) | |
| 197 | 추가: .unwrap_err(); | |
| 198 | 추가: assert!(matches!( | |
| 199 | 추가: failure.cause, | |
| 200 | 추가: Error::Unsupported(Unsupported::MultipleLinks) | |
| 201 | 추가: )); | |
| 202 | 추가: assert_eq!(failure.usage.read_calls, 0); | |
| 203 | 추가: assert_eq!(fs::read(&path).unwrap(), b"new"); | |
| 204 | 추가: sandbox.finish(); | |
| 205 | 추가: } | |
| 206 | 추가: | |
| 207 | 추가: #[test] | |
| 208 | 추가: fn replaced_parent_keeps_pinned_inode_not_new_path_contents() { | |
| 209 | 추가: let sandbox = Sandbox::new(); | |
| 210 | 추가: let parent = sandbox.dir("parent"); | |
| 211 | 추가: let path = sandbox.file("parent/input", b"old"); | |
| 212 | 추가: let original = fs::metadata(&path).unwrap(); | |
| 213 | 추가: let moved = sandbox.path("moved"); | |
| 214 | 추가: let result = capture( | |
| 215 | 추가: Request { | |
| 216 | 추가: path: &path, | |
| 217 | 추가: limits: Limits::default(), | |
| 218 | 추가: }, | |
| 219 | 추가: |point| { | |
| 220 | 추가: if point.stage == Stage::Pinned { | |
| 221 | 추가: fs::rename(&parent, &moved).unwrap(); | |
| 222 | 추가: sandbox.dir("parent"); | |
| 223 | 추가: sandbox.file("parent/input", b"new"); | |
| 224 | 추가: } | |
| 225 | 추가: Ok::<_, Stop<()>>(()) | |
| 226 | 추가: }, | |
| 227 | 추가: ) | |
| 228 | 추가: .unwrap(); | |
| 229 | 추가: assert_eq!(result.bytes(), b"old"); | |
| 230 | 추가: assert_eq!(result.identity().inode(), original.ino()); | |
| 231 | 추가: assert_eq!(result.identity().device(), original.dev()); | |
| 232 | 추가: assert_eq!(fs::read(&path).unwrap(), b"new"); | |
| 233 | 추가: assert_eq!(fs::read(moved.join("input")).unwrap(), b"old"); | |
| 234 | 추가: sandbox.finish(); | |
| 235 | 추가: } | |
| 236 | 추가: | |
| 237 | 추가: #[test] | |
| 238 | 추가: fn returned_snapshot_owns_bytes_after_source_changes() { | |
| 239 | 추가: let sandbox = Sandbox::new(); | |
| 240 | 추가: let path = sandbox.file("input", b"old"); | |
| 241 | 추가: let result = get(&path, Limits::default()).unwrap(); | |
| 242 | 추가: let digest = result.sha256(); | |
| 243 | 추가: fs::write(&path, b"new").unwrap(); | |
| 244 | 추가: assert_eq!(result.bytes(), b"old"); | |
| 245 | 추가: assert_eq!(result.sha256(), digest); | |
| 246 | 추가: assert_eq!(result.into_bytes(), b"old"); | |
| 247 | 추가: sandbox.finish(); | |
| 248 | 추가: } |
| @@ -0,0 +1,202 @@ | ||
| 1 | 추가: use crate::support::*; | |
| 2 | 추가: use snapshot::{Error, IoOperation, Limits, Unsupported, Usage}; | |
| 3 | 추가: use std::{ | |
| 4 | 추가: ffi::{CString, OsString}, | |
| 5 | 추가: fs, | |
| 6 | 추가: os::unix::{ | |
| 7 | 추가: ffi::{OsStrExt, OsStringExt}, | |
| 8 | 추가: fs::symlink, | |
| 9 | 추가: net::UnixListener, | |
| 10 | 추가: }, | |
| 11 | 추가: path::{Path, PathBuf}, | |
| 12 | 추가: }; | |
| 13 | 추가: | |
| 14 | 추가: fn invalid(path: &Path) { | |
| 15 | 추가: let failure = get(path, Limits::default()).unwrap_err(); | |
| 16 | 추가: assert!(matches!(failure.cause, Error::InvalidPath)); | |
| 17 | 추가: assert_eq!(failure.usage, Usage::default()); | |
| 18 | 추가: } | |
| 19 | 추가: | |
| 20 | 추가: #[test] | |
| 21 | 추가: fn empty_path() { | |
| 22 | 추가: invalid(Path::new("")); | |
| 23 | 추가: } | |
| 24 | 추가: | |
| 25 | 추가: #[test] | |
| 26 | 추가: fn relative_path() { | |
| 27 | 추가: invalid(Path::new("relative")); | |
| 28 | 추가: } | |
| 29 | 추가: | |
| 30 | 추가: #[test] | |
| 31 | 추가: fn root_only() { | |
| 32 | 추가: invalid(Path::new("/")); | |
| 33 | 추가: } | |
| 34 | 추가: | |
| 35 | 추가: #[test] | |
| 36 | 추가: fn dot_component() { | |
| 37 | 추가: invalid(Path::new("/owned/./input")); | |
| 38 | 추가: } | |
| 39 | 추가: | |
| 40 | 추가: #[test] | |
| 41 | 추가: fn parent_component() { | |
| 42 | 추가: invalid(Path::new("/owned/../input")); | |
| 43 | 추가: } | |
| 44 | 추가: | |
| 45 | 추가: #[test] | |
| 46 | 추가: fn repeated_slash() { | |
| 47 | 추가: invalid(Path::new("/owned//input")); | |
| 48 | 추가: } | |
| 49 | 추가: | |
| 50 | 추가: #[test] | |
| 51 | 추가: fn trailing_slash() { | |
| 52 | 추가: invalid(Path::new("/owned/input/")); | |
| 53 | 추가: } | |
| 54 | 추가: | |
| 55 | 추가: #[test] | |
| 56 | 추가: fn nul_byte() { | |
| 57 | 추가: invalid(Path::new("/owned/in\0put")); | |
| 58 | 추가: } | |
| 59 | 추가: | |
| 60 | 추가: #[test] | |
| 61 | 추가: fn component_over_255() { | |
| 62 | 추가: invalid(&PathBuf::from(format!("/{}", "x".repeat(256)))); | |
| 63 | 추가: } | |
| 64 | 추가: | |
| 65 | 추가: #[test] | |
| 66 | 추가: fn path_over_4096() { | |
| 67 | 추가: invalid(&PathBuf::from(format!("/{}", "x/".repeat(2049)))); | |
| 68 | 추가: } | |
| 69 | 추가: | |
| 70 | 추가: fn pin_error(path: &Path, code: i32) { | |
| 71 | 추가: let failure = get(path, Limits::default()).unwrap_err(); | |
| 72 | 추가: match failure.cause { | |
| 73 | 추가: Error::Io { operation, source } => { | |
| 74 | 추가: assert_eq!(operation, IoOperation::PinPath); | |
| 75 | 추가: assert_eq!(source.raw_os_error(), Some(code)); | |
| 76 | 추가: } | |
| 77 | 추가: other => panic!("unexpected: {other:?}"), | |
| 78 | 추가: } | |
| 79 | 추가: assert_eq!(failure.usage.open_calls, 1); | |
| 80 | 추가: assert_eq!(failure.usage.metadata_calls, 0); | |
| 81 | 추가: assert_eq!(failure.usage.read_calls, 0); | |
| 82 | 추가: } | |
| 83 | 추가: | |
| 84 | 추가: #[test] | |
| 85 | 추가: fn missing_path_preserves_enoent_and_stage() { | |
| 86 | 추가: let sandbox = Sandbox::new(); | |
| 87 | 추가: pin_error(&sandbox.path("missing"), libc::ENOENT); | |
| 88 | 추가: sandbox.finish(); | |
| 89 | 추가: } | |
| 90 | 추가: | |
| 91 | 추가: #[test] | |
| 92 | 추가: fn regular_parent_component_preserves_enotdir() { | |
| 93 | 추가: let sandbox = Sandbox::new(); | |
| 94 | 추가: let file = sandbox.file("parent", b"unchanged"); | |
| 95 | 추가: pin_error(&file.join("input"), libc::ENOTDIR); | |
| 96 | 추가: assert_eq!(fs::read(file).unwrap(), b"unchanged"); | |
| 97 | 추가: sandbox.finish(); | |
| 98 | 추가: } | |
| 99 | 추가: | |
| 100 | 추가: #[test] | |
| 101 | 추가: fn leaf_symlink_rejected_without_reading_target() { | |
| 102 | 추가: let sandbox = Sandbox::new(); | |
| 103 | 추가: let target = sandbox.file("target", b"unchanged"); | |
| 104 | 추가: let path = sandbox.path("link"); | |
| 105 | 추가: symlink(&target, &path).unwrap(); | |
| 106 | 추가: pin_error(&path, libc::ELOOP); | |
| 107 | 추가: assert_eq!(fs::read(target).unwrap(), b"unchanged"); | |
| 108 | 추가: sandbox.finish(); | |
| 109 | 추가: } | |
| 110 | 추가: | |
| 111 | 추가: #[test] | |
| 112 | 추가: fn ancestor_symlink_rejected() { | |
| 113 | 추가: let sandbox = Sandbox::new(); | |
| 114 | 추가: let parent = sandbox.dir("parent"); | |
| 115 | 추가: sandbox.file("parent/input", b"unchanged"); | |
| 116 | 추가: let link = sandbox.path("alias"); | |
| 117 | 추가: symlink(parent, &link).unwrap(); | |
| 118 | 추가: pin_error(&link.join("input"), libc::ELOOP); | |
| 119 | 추가: sandbox.finish(); | |
| 120 | 추가: } | |
| 121 | 추가: | |
| 122 | 추가: #[test] | |
| 123 | 추가: fn dangling_symlink_preserves_eloop() { | |
| 124 | 추가: let sandbox = Sandbox::new(); | |
| 125 | 추가: let path = sandbox.path("link"); | |
| 126 | 추가: symlink(sandbox.path("missing"), &path).unwrap(); | |
| 127 | 추가: pin_error(&path, libc::ELOOP); | |
| 128 | 추가: sandbox.finish(); | |
| 129 | 추가: } | |
| 130 | 추가: | |
| 131 | 추가: fn unsupported(path: &Path, expected: Unsupported) { | |
| 132 | 추가: let failure = get(path, Limits::default()).unwrap_err(); | |
| 133 | 추가: assert!(matches!(failure.cause, Error::Unsupported(value) if value == expected)); | |
| 134 | 추가: assert_eq!(failure.usage.open_calls, 1); | |
| 135 | 추가: assert_eq!(failure.usage.metadata_calls, 1); | |
| 136 | 추가: assert_eq!(failure.usage.read_calls, 0); | |
| 137 | 추가: } | |
| 138 | 추가: | |
| 139 | 추가: #[test] | |
| 140 | 추가: fn directory_rejected_before_data_open() { | |
| 141 | 추가: let sandbox = Sandbox::new(); | |
| 142 | 추가: unsupported(&sandbox.dir("directory"), Unsupported::FileType); | |
| 143 | 추가: sandbox.finish(); | |
| 144 | 추가: } | |
| 145 | 추가: | |
| 146 | 추가: #[test] | |
| 147 | 추가: fn fifo_without_writer_rejected_before_data_open() { | |
| 148 | 추가: let sandbox = Sandbox::new(); | |
| 149 | 추가: let path = sandbox.path("fifo"); | |
| 150 | 추가: let raw = CString::new(path.as_os_str().as_bytes()).unwrap(); | |
| 151 | 추가: // 작업 전용 경로에 합성 FIFO만 생성함. | |
| 152 | 추가: assert_eq!(unsafe { libc::mkfifo(raw.as_ptr(), 0o600) }, 0); | |
| 153 | 추가: unsupported(&path, Unsupported::FileType); | |
| 154 | 추가: sandbox.finish(); | |
| 155 | 추가: } | |
| 156 | 추가: | |
| 157 | 추가: #[test] | |
| 158 | 추가: fn unix_socket_rejected_before_data_open() { | |
| 159 | 추가: let sandbox = Sandbox::new(); | |
| 160 | 추가: let path = sandbox.path("socket"); | |
| 161 | 추가: let socket = UnixListener::bind(&path).unwrap(); | |
| 162 | 추가: unsupported(&path, Unsupported::FileType); | |
| 163 | 추가: drop(socket); | |
| 164 | 추가: sandbox.finish(); | |
| 165 | 추가: } | |
| 166 | 추가: | |
| 167 | 추가: #[test] | |
| 168 | 추가: fn multiple_hard_links_rejected_and_contents_preserved() { | |
| 169 | 추가: let sandbox = Sandbox::new(); | |
| 170 | 추가: let path = sandbox.file("input", b"unchanged"); | |
| 171 | 추가: let link = sandbox.path("hardlink"); | |
| 172 | 추가: fs::hard_link(&path, &link).unwrap(); | |
| 173 | 추가: unsupported(&path, Unsupported::MultipleLinks); | |
| 174 | 추가: assert_eq!(fs::read(path).unwrap(), b"unchanged"); | |
| 175 | 추가: assert_eq!(fs::read(link).unwrap(), b"unchanged"); | |
| 176 | 추가: sandbox.finish(); | |
| 177 | 추가: } | |
| 178 | 추가: | |
| 179 | 추가: #[test] | |
| 180 | 추가: fn non_utf8_linux_name_is_supported() { | |
| 181 | 추가: let sandbox = Sandbox::new(); | |
| 182 | 추가: let path = sandbox.root.join(OsString::from_vec(vec![b'i', 0xff])); | |
| 183 | 추가: fs::write(&path, b"abc").unwrap(); | |
| 184 | 추가: assert_eq!(get(&path, Limits::default()).unwrap().bytes(), b"abc"); | |
| 185 | 추가: sandbox.finish(); | |
| 186 | 추가: } | |
| 187 | 추가: | |
| 188 | 추가: #[test] | |
| 189 | 추가: fn linux_backslash_and_colon_are_name_bytes() { | |
| 190 | 추가: let sandbox = Sandbox::new(); | |
| 191 | 추가: let path = sandbox.file("a\\b:c", b"abc"); | |
| 192 | 추가: assert_eq!(get(&path, Limits::default()).unwrap().bytes(), b"abc"); | |
| 193 | 추가: sandbox.finish(); | |
| 194 | 추가: } | |
| 195 | 추가: | |
| 196 | 추가: #[test] | |
| 197 | 추가: fn component_255_bytes_is_supported() { | |
| 198 | 추가: let sandbox = Sandbox::new(); | |
| 199 | 추가: let path = sandbox.file(&"x".repeat(255), b"abc"); | |
| 200 | 추가: assert_eq!(get(&path, Limits::default()).unwrap().bytes(), b"abc"); | |
| 201 | 추가: sandbox.finish(); | |
| 202 | 추가: } |
| @@ -0,0 +1,59 @@ | ||
| 1 | 추가: { | |
| 2 | 추가: "head": "b7c3d5575943f8caab8bbdcf465c278c3e7059d1", | |
| 3 | 추가: "files": [ | |
| 4 | 추가: { | |
| 5 | 추가: "path": "experiments/rust-file-snapshot/Cargo.lock", | |
| 6 | 추가: "git_blob": "f78b06aafe24e649c3b8dbf1e80f84875665916d", | |
| 7 | 추가: "sha256": "ba55ac17dc748d1f91d7a6e5d5ebb4c6b9c84d09173a17d4cac31cf149fb771b", | |
| 8 | 추가: "mode": "100644" | |
| 9 | 추가: }, | |
| 10 | 추가: { | |
| 11 | 추가: "path": "experiments/rust-file-snapshot/Cargo.toml", | |
| 12 | 추가: "git_blob": "5f13cef3e22861c18da16a0aa45ed990a448d1bf", | |
| 13 | 추가: "sha256": "e641f091c0acabd3e6fbfa3ed6bf53e05be3ca6c2fc90d67980721b378840f0f", | |
| 14 | 추가: "mode": "100644" | |
| 15 | 추가: }, | |
| 16 | 추가: { | |
| 17 | 추가: "path": "experiments/rust-file-snapshot/LICENSE", | |
| 18 | 추가: "git_blob": "5014abac33298592fd3450b51a9b414191e1aabc", | |
| 19 | 추가: "sha256": "0714945e52a4d5b560c02c9a18478519f8c4e2572cbf87bd6d52adcfb2b63c62", | |
| 20 | 추가: "mode": "100644" | |
| 21 | 추가: }, | |
| 22 | 추가: { | |
| 23 | 추가: "path": "experiments/rust-file-snapshot/SHA256SUMS", | |
| 24 | 추가: "git_blob": "76201cbad9d40111091cb320744f59bb07b4bc65", | |
| 25 | 추가: "sha256": "668b1c3f140a033a6a0768b84ec52f111ee5fbfaf707632d2fc9a5a380758120", | |
| 26 | 추가: "mode": "100644" | |
| 27 | 추가: }, | |
| 28 | 추가: { | |
| 29 | 추가: "path": "experiments/rust-file-snapshot/THIRD-PARTY-NOTICES.txt", | |
| 30 | 추가: "git_blob": "c18cb9011479d97d247bf403c128e5923fa769c9", | |
| 31 | 추가: "sha256": "066b8c0623b870c0c3998a0499b0323f3cfe8d3cfd60bf6bbc833be0e523a06e", | |
| 32 | 추가: "mode": "100644" | |
| 33 | 추가: }, | |
| 34 | 추가: { | |
| 35 | 추가: "path": "experiments/rust-file-snapshot/contract.json", | |
| 36 | 추가: "git_blob": "93c7b53f2441eee3d98db58dcca8ece47b1094d6", | |
| 37 | 추가: "sha256": "8b54705382c3af1168b684fbcf3e25efd256eb145c636972fe6e26b8cb898ff2", | |
| 38 | 추가: "mode": "100644" | |
| 39 | 추가: }, | |
| 40 | 추가: { | |
| 41 | 추가: "path": "experiments/rust-file-snapshot/dependencies.json", | |
| 42 | 추가: "git_blob": "cf8c2f473069573ba29b9cf278d7a09eac83adca", | |
| 43 | 추가: "sha256": "ea113f15ec27f9903eed985e1e55f49114b9867b0c7c707e2cd15009fa02c6c0", | |
| 44 | 추가: "mode": "100644" | |
| 45 | 추가: }, | |
| 46 | 추가: { | |
| 47 | 추가: "path": "experiments/rust-file-snapshot/src/lib.rs", | |
| 48 | 추가: "git_blob": "b119facbf8cef61cb1877b7cef9f921f4d63d311", | |
| 49 | 추가: "sha256": "e087714fc3e30b8efdd1cf16e1d8944ebc3518c757b8917d6e32d3b3dc3936c9", | |
| 50 | 추가: "mode": "100644" | |
| 51 | 추가: }, | |
| 52 | 추가: { | |
| 53 | 추가: "path": "experiments/rust-file-snapshot/src/linux.rs", | |
| 54 | 추가: "git_blob": "ed9af89904de5a4b44673b098e944b35faa3075f", | |
| 55 | 추가: "sha256": "88aa71907bfd07ef61697eb2c71e8ffbdc178c68ea9fcae8d26957be4751fa21", | |
| 56 | 추가: "mode": "100644" | |
| 57 | 추가: } | |
| 58 | 추가: ] | |
| 59 | 추가: } |
| @@ -0,0 +1,137 @@ | ||
| 1 | 추가: import argparse | |
| 2 | 추가: import hashlib | |
| 3 | 추가: import json | |
| 4 | 추가: import pathlib | |
| 5 | 추가: import re | |
| 6 | 추가: import sys | |
| 7 | 추가: import tomllib | |
| 8 | 추가: | |
| 9 | 추가: BASE = pathlib.Path(__file__).resolve().parent | |
| 10 | 추가: ROOT = BASE.parents[1] | |
| 11 | 추가: HEAD = "b7c3d5575943f8caab8bbdcf465c278c3e7059d1" | |
| 12 | 추가: SOURCE = ROOT / "experiments/rust-file-snapshot" | |
| 13 | 추가: SOURCE_MANIFEST = "668b1c3f140a033a6a0768b84ec52f111ee5fbfaf707632d2fc9a5a380758120" | |
| 14 | 추가: FILES = { | |
| 15 | 추가: "Cargo.toml", "Cargo.lock", "main.rs", "support.rs", "boundaries.rs", | |
| 16 | 추가: "paths.rs", "mutations.rs", "control.rs", "source-pins.json", | |
| 17 | 추가: "contract.json", "static_check.py", "static_check_helper_tests.py", | |
| 18 | 추가: } | |
| 19 | 추가: MODULES = ("boundaries", "paths", "mutations", "control") | |
| 20 | 추가: GUARD = "최적화 모드에서는 정적 검사를 실행할 수 없음" | |
| 21 | 추가: | |
| 22 | 추가: | |
| 23 | 추가: def require(condition, message): | |
| 24 | 추가: if not condition: | |
| 25 | 추가: raise RuntimeError(message) | |
| 26 | 추가: | |
| 27 | 추가: | |
| 28 | 추가: def digest(raw): | |
| 29 | 추가: return hashlib.sha256(raw).hexdigest() | |
| 30 | 추가: | |
| 31 | 추가: | |
| 32 | 추가: def parse_manifest(text, expected_paths): | |
| 33 | 추가: rows = {} | |
| 34 | 추가: for line in text.splitlines(): | |
| 35 | 추가: match = re.fullmatch(r"([0-9a-f]{64}) ([A-Za-z0-9_./-]+)", line) | |
| 36 | 추가: require(match is not None, "잘못된 manifest 행") | |
| 37 | 추가: value, name = match.groups() | |
| 38 | 추가: path = pathlib.PurePosixPath(name) | |
| 39 | 추가: require(not path.is_absolute() and ".." not in path.parts | |
| 40 | 추가: and str(path) == name and name not in rows, "중복 또는 잘못된 경로") | |
| 41 | 추가: rows[name] = value | |
| 42 | 추가: require(set(rows) == set(expected_paths), "manifest 경로 불일치") | |
| 43 | 추가: return rows | |
| 44 | 추가: | |
| 45 | 추가: | |
| 46 | 추가: def hashes(): | |
| 47 | 추가: result = {} | |
| 48 | 추가: for name in sorted(FILES | {"SHA256SUMS"}): | |
| 49 | 추가: path = BASE / name | |
| 50 | 추가: require(not path.is_symlink(), "시험 파일 링크 거부") | |
| 51 | 추가: result[name] = digest(path.read_bytes()) | |
| 52 | 추가: return result | |
| 53 | 추가: | |
| 54 | 추가: | |
| 55 | 추가: def verify_sources(): | |
| 56 | 추가: pins = json.loads((BASE / "source-pins.json").read_text()) | |
| 57 | 추가: require(pins["head"] == HEAD and len(pins["files"]) == 9, "고정 source 기준 불일치") | |
| 58 | 추가: names = [row["path"] for row in pins["files"]] | |
| 59 | 추가: require(len(set(names)) == 9, "source 경로 중복") | |
| 60 | 추가: result = {} | |
| 61 | 추가: for row in pins["files"]: | |
| 62 | 추가: path = ROOT / row["path"] | |
| 63 | 추가: require(path.resolve().is_relative_to(SOURCE) and not path.is_symlink(), "source 경로 이탈") | |
| 64 | 추가: raw = path.read_bytes() | |
| 65 | 추가: require(digest(raw) == row["sha256"], "source SHA256 불일치") | |
| 66 | 추가: blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() | |
| 67 | 추가: require(blob == row["git_blob"] and row["mode"] == "100644", "source blob 불일치") | |
| 68 | 추가: result[row["path"]] = digest(raw) | |
| 69 | 추가: manifest = (SOURCE / "SHA256SUMS").read_bytes() | |
| 70 | 추가: require(digest(manifest) == SOURCE_MANIFEST, "source manifest 불일치") | |
| 71 | 추가: entries = parse_manifest(manifest.decode(), set(names) - {"experiments/rust-file-snapshot/SHA256SUMS"}) | |
| 72 | 추가: for name, value in entries.items(): | |
| 73 | 추가: require(digest((ROOT / name).read_bytes()) == value, "source manifest 파일 불일치") | |
| 74 | 추가: return result | |
| 75 | 추가: | |
| 76 | 추가: | |
| 77 | 추가: def main(): | |
| 78 | 추가: if sys.flags.optimize: | |
| 79 | 추가: raise RuntimeError(GUARD) | |
| 80 | 추가: parser = argparse.ArgumentParser() | |
| 81 | 추가: parser.add_argument("--manifest-sha256", required=True) | |
| 82 | 추가: parser.add_argument("--metadata", type=pathlib.Path) | |
| 83 | 추가: args = parser.parse_args() | |
| 84 | 추가: before = hashes() | |
| 85 | 추가: require(before["SHA256SUMS"] == args.manifest_sha256, "시험 manifest 불일치") | |
| 86 | 추가: rows = parse_manifest((BASE / "SHA256SUMS").read_text(), FILES) | |
| 87 | 추가: require(all(before[name] == value for name, value in rows.items()), "시험 파일 변경") | |
| 88 | 추가: sources = verify_sources() | |
| 89 | 추가: contract = json.loads((BASE / "contract.json").read_text()) | |
| 90 | 추가: require(contract["source_head"] == HEAD, "계약 head 불일치") | |
| 91 | 추가: names = [] | |
| 92 | 추가: for module in MODULES: | |
| 93 | 추가: source = (BASE / (module + ".rs")).read_text() | |
| 94 | 추가: found = re.findall(r"#\[test\]\s*fn ([a-z0-9_]+)\(", source) | |
| 95 | 추가: require(len(found) == source.count("#[test]"), "시험 선언 분석 실패") | |
| 96 | 추가: names.extend(module + "::" + name for name in found) | |
| 97 | 추가: require(len(names) == len(set(names)) == contract["declared_test_count"] == 72, "선언 수 불일치") | |
| 98 | 추가: require(sorted(names) == contract["test_names"] == sorted(contract["evidence_classes"]), "이름 집합 불일치") | |
| 99 | 추가: for path in BASE.glob("*.rs"): | |
| 100 | 추가: source = path.read_text() | |
| 101 | 추가: require("#[ignore" not in source and "#[should_panic" not in source, "시험 제외 금지") | |
| 102 | 추가: require(not re.search(r"include!|#\[path|Command::|execveat|\bmknod\b", source), "범위 밖 Rust 경계") | |
| 103 | 추가: manifest = tomllib.loads((BASE / "Cargo.toml").read_text()) | |
| 104 | 추가: require(manifest["package"]["autotests"] is False, "자동 시험 발견 금지") | |
| 105 | 추가: require(manifest["test"] == [{"name": "snapshot_public_api", "path": "main.rs"}], "target 불일치") | |
| 106 | 추가: require(manifest["dependencies"] == { | |
| 107 | 추가: "snapshot": {"package": "zipelo-file-snapshot", "path": "../../experiments/rust-file-snapshot"}, | |
| 108 | 추가: "libc": {"version": "=0.2.191", "default-features": False, "features": ["std"]}, | |
| 109 | 추가: }, "직접 의존성 변경") | |
| 110 | 추가: normal = lambda rows: sorted(rows, key=lambda row: (row["name"], row["version"])) | |
| 111 | 추가: original = tomllib.loads((SOURCE / "Cargo.lock").read_text())["package"] | |
| 112 | 추가: locked = tomllib.loads((BASE / "Cargo.lock").read_text())["package"] | |
| 113 | 추가: root = {"name": "zipelo-file-snapshot-regressions", "version": "0.1.0", "dependencies": ["libc", "zipelo-file-snapshot"]} | |
| 114 | 추가: require(normal(locked) == normal(original + [root]), "기존 lock graph 변경") | |
| 115 | 추가: if args.metadata: | |
| 116 | 추가: require(args.metadata.resolve().is_relative_to(BASE), "metadata 위치 이탈") | |
| 117 | 추가: metadata = json.loads(args.metadata.read_text()) | |
| 118 | 추가: packages = {p["id"]: p for p in metadata["packages"]} | |
| 119 | 추가: root_package = packages[metadata["resolve"]["root"]] | |
| 120 | 추가: require(root_package["name"] == root["name"], "metadata root 불일치") | |
| 121 | 추가: require(len(root_package["targets"]) == 1 and root_package["targets"][0]["kind"] == ["test"], "target 추가") | |
| 122 | 추가: registry = {(p["name"], p["version"], p["checksum"]) for p in locked if "source" in p} | |
| 123 | 추가: expected = {(p["name"], p["version"], p["checksum"]) for p in json.loads((SOURCE / "dependencies.json").read_text())["registry_packages"]} | |
| 124 | 추가: require(registry == expected, "registry graph 변경") | |
| 125 | 추가: for node in metadata["resolve"]["nodes"]: | |
| 126 | 추가: package = packages[node["id"]] | |
| 127 | 추가: if package["name"] == "sha2": | |
| 128 | 추가: require(sorted(node["features"]) == ["force-soft", "std"], "sha2 feature 변경") | |
| 129 | 추가: if package["name"] == "libc": | |
| 130 | 추가: require(sorted(node["features"]) == ["std"], "libc feature 변경") | |
| 131 | 추가: require(verify_sources() == sources and hashes() == before, "검사 중 입력 변경") | |
| 132 | 추가: print(json.dumps({"head": HEAD, "source_files": 9, "declared": len(names), | |
| 133 | 추가: "rust_compiled": False, "rust_executed": 0, "inputs_unchanged": True})) | |
| 134 | 추가: | |
| 135 | 추가: | |
| 136 | 추가: if __name__ == "__main__": | |
| 137 | 추가: main() |
| @@ -0,0 +1,102 @@ | ||
| 1 | 추가: import json | |
| 2 | 추가: import os | |
| 3 | 추가: import pathlib | |
| 4 | 추가: import runpy | |
| 5 | 추가: import subprocess | |
| 6 | 추가: import sys | |
| 7 | 추가: import unittest | |
| 8 | 추가: | |
| 9 | 추가: BASE = pathlib.Path(__file__).resolve().parent | |
| 10 | 추가: CHECKER = BASE / "static_check.py" | |
| 11 | 추가: CODE = """ | |
| 12 | 추가: import json, pathlib, runpy, sys | |
| 13 | 추가: from unittest.mock import patch | |
| 14 | 추가: scope = runpy.run_path(sys.argv[1]) | |
| 15 | 추가: calls = [] | |
| 16 | 추가: def blocked(*args, **kwargs): | |
| 17 | 추가: calls.append("side_effect") | |
| 18 | 추가: raise RuntimeError("side_effect") | |
| 19 | 추가: with patch("argparse.ArgumentParser", blocked), \ | |
| 20 | 추가: patch.object(pathlib.Path, "read_bytes", blocked), \ | |
| 21 | 추가: patch.object(pathlib.Path, "read_text", blocked), \ | |
| 22 | 추가: patch.object(runpy, "run_path", blocked): | |
| 23 | 추가: try: | |
| 24 | 추가: scope["main"]() | |
| 25 | 추가: except RuntimeError as error: | |
| 26 | 추가: print(json.dumps({"message": str(error), "calls": calls, "optimize": sys.flags.optimize})) | |
| 27 | 추가: """ | |
| 28 | 추가: | |
| 29 | 추가: | |
| 30 | 추가: class StaticHelperTests(unittest.TestCase): | |
| 31 | 추가: def child(self, environment_mode=False, flag=False, cli=False): | |
| 32 | 추가: environment = os.environ.copy() | |
| 33 | 추가: environment.pop("PYTHONOPTIMIZE", None) | |
| 34 | 추가: environment["PYTHONDONTWRITEBYTECODE"] = "1" | |
| 35 | 추가: if environment_mode: | |
| 36 | 추가: environment["PYTHONOPTIMIZE"] = "1" | |
| 37 | 추가: command = [sys.executable, "-B"] + (["-O"] if flag else []) | |
| 38 | 추가: command += [str(CHECKER)] if cli else ["-c", CODE, str(CHECKER)] | |
| 39 | 추가: return subprocess.run(command, env=environment, cwd=BASE, | |
| 40 | 추가: capture_output=True, text=True, timeout=10) | |
| 41 | 추가: | |
| 42 | 추가: def probe(self, **mode): | |
| 43 | 추가: result = self.child(**mode) | |
| 44 | 추가: self.assertEqual(result.returncode, 0, result.stderr) | |
| 45 | 추가: self.assertEqual(result.stderr, "") | |
| 46 | 추가: self.assertEqual(json.loads(result.stdout), { | |
| 47 | 추가: "message": "최적화 모드에서는 정적 검사를 실행할 수 없음", | |
| 48 | 추가: "calls": [], "optimize": 1, | |
| 49 | 추가: }) | |
| 50 | 추가: | |
| 51 | 추가: def test_flag_stops_before_reads_arguments_and_generation(self): | |
| 52 | 추가: self.probe(flag=True) | |
| 53 | 추가: | |
| 54 | 추가: def test_environment_stops_before_reads_arguments_and_generation(self): | |
| 55 | 추가: self.probe(environment_mode=True) | |
| 56 | 추가: | |
| 57 | 추가: def test_normal_mode_reaches_parser(self): | |
| 58 | 추가: result = self.child() | |
| 59 | 추가: self.assertEqual(result.returncode, 0, result.stderr) | |
| 60 | 추가: self.assertEqual(json.loads(result.stdout), { | |
| 61 | 추가: "message": "side_effect", "calls": ["side_effect"], "optimize": 0, | |
| 62 | 추가: }) | |
| 63 | 추가: | |
| 64 | 추가: def test_flag_cli_fails_before_required_arguments(self): | |
| 65 | 추가: result = self.child(flag=True, cli=True) | |
| 66 | 추가: self.assertNotEqual(result.returncode, 0) | |
| 67 | 추가: self.assertEqual(result.stdout, "") | |
| 68 | 추가: self.assertIn("RuntimeError: 최적화 모드", result.stderr) | |
| 69 | 추가: self.assertNotIn("arguments are required", result.stderr) | |
| 70 | 추가: | |
| 71 | 추가: def test_environment_cli_fails_before_required_arguments(self): | |
| 72 | 추가: result = self.child(environment_mode=True, cli=True) | |
| 73 | 추가: self.assertNotEqual(result.returncode, 0) | |
| 74 | 추가: self.assertEqual(result.stdout, "") | |
| 75 | 추가: self.assertIn("RuntimeError: 최적화 모드", result.stderr) | |
| 76 | 추가: | |
| 77 | 추가: def reject(self, content, paths): | |
| 78 | 추가: parse = runpy.run_path(str(CHECKER))["parse_manifest"] | |
| 79 | 추가: with self.assertRaises(RuntimeError): | |
| 80 | 추가: parse(content, paths) | |
| 81 | 추가: | |
| 82 | 추가: def test_duplicate_manifest_rows_rejected(self): | |
| 83 | 추가: line = "a" * 64 + " main.rs\n" | |
| 84 | 추가: self.reject(line + line, {"main.rs"}) | |
| 85 | 추가: | |
| 86 | 추가: def test_missing_manifest_path_rejected(self): | |
| 87 | 추가: self.reject("a" * 64 + " main.rs\n", {"main.rs", "support.rs"}) | |
| 88 | 추가: | |
| 89 | 추가: def test_parent_path_rejected(self): | |
| 90 | 추가: self.reject("a" * 64 + " ../main.rs\n", {"../main.rs"}) | |
| 91 | 추가: | |
| 92 | 추가: def test_repository_relative_source_manifest_path(self): | |
| 93 | 추가: parse = runpy.run_path(str(CHECKER))["parse_manifest"] | |
| 94 | 추가: name = "experiments/rust-file-snapshot/src/lib.rs" | |
| 95 | 추가: self.assertEqual(parse("a" * 64 + " " + name + "\n", {name}), {name: "a" * 64}) | |
| 96 | 추가: | |
| 97 | 추가: def test_malformed_digest_rejected(self): | |
| 98 | 추가: self.reject("g" * 64 + " main.rs\n", {"main.rs"}) | |
| 99 | 추가: | |
| 100 | 추가: | |
| 101 | 추가: if __name__ == "__main__": | |
| 102 | 추가: unittest.main(verbosity=2) |
| @@ -0,0 +1,90 @@ | ||
| 1 | 추가: use snapshot::{Error, Failure, FileSnapshot, Limits, Request, Stop, capture}; | |
| 2 | 추가: use std::{ | |
| 3 | 추가: fs::{self, DirBuilder, OpenOptions}, | |
| 4 | 추가: io::Write, | |
| 5 | 추가: os::unix::fs::{DirBuilderExt, MetadataExt, OpenOptionsExt}, | |
| 6 | 추가: path::{Path, PathBuf}, | |
| 7 | 추가: sync::atomic::{AtomicU64, Ordering}, | |
| 8 | 추가: }; | |
| 9 | 추가: | |
| 10 | 추가: static NEXT: AtomicU64 = AtomicU64::new(1); | |
| 11 | 추가: | |
| 12 | 추가: pub struct Sandbox { | |
| 13 | 추가: pub root: PathBuf, | |
| 14 | 추가: identity: (u64, u64), | |
| 15 | 추가: } | |
| 16 | 추가: | |
| 17 | 추가: impl Sandbox { | |
| 18 | 추가: pub fn new() -> Self { | |
| 19 | 추가: let parent = Path::new(env!("CARGO_MANIFEST_DIR")).join("runs"); | |
| 20 | 추가: let metadata = fs::symlink_metadata(&parent).expect("runner가 runs 디렉터리를 준비해야 함"); | |
| 21 | 추가: assert!(metadata.is_dir() && !metadata.file_type().is_symlink()); | |
| 22 | 추가: assert_eq!(metadata.mode() & 0o777, 0o700); | |
| 23 | 추가: assert_eq!(parent.canonicalize().unwrap(), parent); | |
| 24 | 추가: let root = parent.join(format!( | |
| 25 | 추가: "case-{}-{}", | |
| 26 | 추가: std::process::id(), | |
| 27 | 추가: NEXT.fetch_add(1, Ordering::Relaxed) | |
| 28 | 추가: )); | |
| 29 | 추가: DirBuilder::new().mode(0o700).create(&root).unwrap(); | |
| 30 | 추가: let metadata = fs::symlink_metadata(&root).unwrap(); | |
| 31 | 추가: Self { | |
| 32 | 추가: root, | |
| 33 | 추가: identity: (metadata.dev(), metadata.ino()), | |
| 34 | 추가: } | |
| 35 | 추가: } | |
| 36 | 추가: | |
| 37 | 추가: pub fn path(&self, name: &str) -> PathBuf { | |
| 38 | 추가: self.root.join(name) | |
| 39 | 추가: } | |
| 40 | 추가: | |
| 41 | 추가: pub fn file(&self, name: &str, bytes: &[u8]) -> PathBuf { | |
| 42 | 추가: let path = self.path(name); | |
| 43 | 추가: let mut file = OpenOptions::new() | |
| 44 | 추가: .write(true) | |
| 45 | 추가: .create_new(true) | |
| 46 | 추가: .mode(0o600) | |
| 47 | 추가: .open(&path) | |
| 48 | 추가: .unwrap(); | |
| 49 | 추가: file.write_all(bytes).unwrap(); | |
| 50 | 추가: file.sync_all().unwrap(); | |
| 51 | 추가: path | |
| 52 | 추가: } | |
| 53 | 추가: | |
| 54 | 추가: pub fn dir(&self, name: &str) -> PathBuf { | |
| 55 | 추가: let path = self.path(name); | |
| 56 | 추가: DirBuilder::new().mode(0o700).create(&path).unwrap(); | |
| 57 | 추가: path | |
| 58 | 추가: } | |
| 59 | 추가: | |
| 60 | 추가: pub fn finish(self) { | |
| 61 | 추가: let metadata = fs::symlink_metadata(&self.root).unwrap(); | |
| 62 | 추가: assert!(metadata.is_dir() && !metadata.file_type().is_symlink()); | |
| 63 | 추가: assert_eq!((metadata.dev(), metadata.ino()), self.identity); | |
| 64 | 추가: fs::remove_dir_all(&self.root).unwrap(); | |
| 65 | 추가: assert!(!self.root.exists()); | |
| 66 | 추가: } | |
| 67 | 추가: } | |
| 68 | 추가: | |
| 69 | 추가: pub fn pattern(length: usize) -> Vec<u8> { | |
| 70 | 추가: (0..length).map(|i| ((i * 37 + 11) % 251) as u8).collect() | |
| 71 | 추가: } | |
| 72 | 추가: | |
| 73 | 추가: pub fn get(path: &Path, limits: Limits) -> Result<FileSnapshot, Failure<()>> { | |
| 74 | 추가: capture(Request { path, limits }, |_| Ok::<_, Stop<()>>(())) | |
| 75 | 추가: } | |
| 76 | 추가: | |
| 77 | 추가: pub fn expect_usage(snapshot: &FileSnapshot, length: usize) { | |
| 78 | 추가: let usage = snapshot.usage(); | |
| 79 | 추가: assert_eq!(usage.open_calls, 4); | |
| 80 | 추가: assert_eq!(usage.metadata_calls, 5); | |
| 81 | 추가: assert_eq!(usage.read_calls, 2 * (length as u64).div_ceil(65_536) + 2); | |
| 82 | 추가: assert_eq!(usage.reserved_read_bytes, 2 * length as u64 + 2); | |
| 83 | 추가: assert_eq!(usage.actual_read_bytes, 2 * length as u64); | |
| 84 | 추가: assert_eq!(usage.compared_bytes, length as u64); | |
| 85 | 추가: } | |
| 86 | 추가: | |
| 87 | 추가: pub fn changed(failure: Failure<()>, expected: snapshot::Changed) -> snapshot::Usage { | |
| 88 | 추가: assert!(matches!(failure.cause, Error::Changed(value) if value == expected)); | |
| 89 | 추가: failure.usage | |
| 90 | 추가: } |