Debian Codegraph @

tests/integration/run_integration_test.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 #
3 # Integration test for HTTPDirFS
4 #
5 # This script:
6 # 1. Generates test files with various filenames (including non-alphanumeric)
7 # 2. Starts an HTTP server with Range request support
8 # 3. Mounts the HTTP directory with httpdirfs
9 # 4. Verifies file listing, content integrity (SHA-256), and sizes
10 # 5. Tests cache mode with multithreaded reads on a large file
11 # 6. Cleans up (unmount, stop server, remove temp files)
12 #
13 # Usage: ./run_integration_test.sh [path_to_httpdirfs_binary]
14 #
15 # Exit codes:
16 # 0 - All tests passed
17 # 1 - Test failure or setup error
18
19 set -euo pipefail
20
21 # ─── Configuration ───────────────────────────────────────────────────────────
22
23 SCRIPT_DIR="$(cd "$(dirnamescip-shell system . . dirname. "${BASH_SOURCE[0]}")" && pwdscip-shell system . . pwd.)"
24 HTTP_PORT="${HTTPDIRFS_TEST_PORT:-0}"
25
26 # Parse options
27 MODE="all"
28 HTTPDIRFS_BIN=""
29
30 while [[ $# -gt 0 ]]; do
31 case "$1" in
32 --short)
33 MODE="short"
34 shift
35 ;;
36 --long)
37 MODE="long"
38 shift
39 ;;
40 -*)
41 echoscip-shell system . . echo. -e "\033[0;31m[ERROR]\033[0m Unknown option: $1" >&2
42 exit 1
43 ;;
44 *)
45 if [[ -z "${HTTPDIRFS_BIN}" ]]; then
46 HTTPDIRFS_BIN="$1"
47 else
48 echoscip-shell system . . echo. -e "\033[0;31m[ERROR]\033[0m Multiple binary paths specified or extra arguments: $*" >&2
49 exit 1
50 fi
51 shift
52 ;;
53 esac
54 done
55
56 # Colours for output
57 RED='\033[0;31m'
58 GREEN='\033[0;32m'
59 YELLOW='\033[1;33m'
60 NC='\033[0m' # No Colour
61
62 PASS_COUNT=0
63 FAIL_COUNT=0
64 SKIP_COUNT=0
65
66 # ─── Helpers ─────────────────────────────────────────────────────────────────
67
68 log_infoscip-shell shell shell-project 0.0.0 log_info().() { echoscip-shell system . . echo. -e "${GREEN}[INFO]${NC} $*"; }
69 log_warnscip-shell shell shell-project 0.0.0 log_warn().() { echoscip-shell system . . echo. -e "${YELLOW}[WARN]${NC} $*"; }
70 log_errorscip-shell shell shell-project 0.0.0 log_error().() { echoscip-shell system . . echo. -e "${RED}[ERROR]${NC} $*"; }
71
72 passscip-shell shell shell-project 0.0.0 pass().() { PASS_COUNT=$((PASS_COUNT + 1)); echoscip-shell system . . echo. -e " ${GREEN}PASS${NC}: $*"; }
73 failscip-shell shell shell-project 0.0.0 fail().() { FAIL_COUNT=$((FAIL_COUNT + 1)); echoscip-shell system . . echo. -e " ${RED}FAIL${NC}: $*"; }
74 skipscip-shell shell shell-project 0.0.0 skip().() { SKIP_COUNT=$((SKIP_COUNT + 1)); echoscip-shell system . . echo. -e " ${YELLOW}SKIP${NC}: $*"; }
75
76 do_unmountscip-shell shell shell-project 0.0.0 do_unmount().() {
77 local mnt="$1"
78 fusermount3 -u "${mnt}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || \
79 fusermount -u "${mnt}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || \
80 umount "${mnt}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
81 }
82
83 cleanupscip-shell shell shell-project 0.0.0 cleanup().() {
84 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Cleaning up..."
85
86 # Unmount if still mounted
87 if [[ -n "${MOUNT_DIR:-}" ]] && mountpointscip-shell system . . mountpoint. -q "${MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
88 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${MOUNT_DIR}"
89 sleepscip-shell system . . sleep. 1
90 fi
91 if [[ -n "${CACHE_MOUNT_DIR:-}" ]] \
92 && mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
93 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${CACHE_MOUNT_DIR}"
94 sleepscip-shell system . . sleep. 1
95 fi
96
97 # Stop HTTP server
98 if [[ -n "${HTTP_PID:-}" ]] && killscip-shell system . . kill. -0 "${HTTP_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
99 killscip-shell system . . kill. "${HTTP_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
100 wait "${HTTP_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
101 fi
102
103 # Remove temp directories
104 if [[ -n "${WORK_DIR:-}" && -d "${WORK_DIR}" ]]; then
105 rmscip-shell system . . rm. -rf "${WORK_DIR}"
106 fi
107
108 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Cleanup complete."
109 }
110
111 trap cleanup EXIT
112
113 # ─── Precondition checks ────────────────────────────────────────────────────
114
115 if [[ -z "${HTTPDIRFS_BIN}" ]]; then
116 log_errorscip-shell shell shell-project 0.0.0 log_error(). "Usage: $0 <path_to_httpdirfs_binary>"
117 exit 1
118 fi
119
120 if [[ ! -x "${HTTPDIRFS_BIN}" ]]; then
121 log_errorscip-shell shell shell-project 0.0.0 log_error(). "httpdirfs binary not found or not executable: ${HTTPDIRFS_BIN}"
122 exit 1
123 fi
124
125 if [[ ! -e /dev/fuse ]]; then
126 log_warnscip-shell shell shell-project 0.0.0 log_warn(). "/dev/fuse not found — FUSE is not available, skipping tests.scip-shell filesystem . . `/dev/fuse not found — FUSE is not available, skipping tests.`."
127 exit 0
128 fi
129
130 if ! command -v python3 &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
131 log_errorscip-shell shell shell-project 0.0.0 log_error(). "python3 is required but not found."
132 exit 1
133 fi
134
135 if ! command -v fusermount3 &>/dev/nullscip-shell filesystem . . `/dev/null`. && ! command -v fusermount &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
136 log_errorscip-shell shell shell-project 0.0.0 log_error(). "fusermount3 (or fusermount) is required but not found."
137 exit 1
138 fi
139
140 # ─── Setup ───────────────────────────────────────────────────────────────────
141
142 WORK_DIR="$(mktempscip-shell system . . mktemp. -d /tmp/httpdirfs-integration-test.XXXXXXscip-shell filesystem . . `/tmp/httpdirfs-integration-test.XXXXXX`.)"
143 SERVE_DIR="${WORK_DIR}/serve"
144 MOUNT_DIR="${WORK_DIR}/mnt"
145 CACHE_MOUNT_DIR="${WORK_DIR}/cache_mnt"
146 CACHE_DIR="${WORK_DIR}/cache"
147 MANIFEST="${SERVE_DIR}/manifest.json"
148 MOUNT_TIMEOUT=15
149
150 mkdirscip-shell system . . mkdir. -p "${SERVE_DIR}" "${MOUNT_DIR}" "${CACHE_MOUNT_DIR}" "${CACHE_DIR}"
151
152 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Work directory: ${WORK_DIR}"
153 log_infoscip-shell shell shell-project 0.0.0 log_info(). "httpdirfs binary: ${HTTPDIRFS_BIN}"
154
155 # ─── Step 1: Generate test files ────────────────────────────────────────────
156
157 if [[ "${MODE}" == "short" ]]; then
158 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Generating test files (excluding 1 GB large file)..."
159 python3scip-shell system . . python3. "${SCRIPT_DIR}/generate_test_files.py" "${SERVE_DIR}" --short
160 elif [[ "${MODE}" == "long" ]]; then
161 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Generating test files (1 GB large file only)..."
162 python3scip-shell system . . python3. "${SCRIPT_DIR}/generate_test_files.py" "${SERVE_DIR}" --long
163 else
164 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Generating all test files (including 1 GB large file)..."
165 python3scip-shell system . . python3. "${SCRIPT_DIR}/generate_test_files.py" "${SERVE_DIR}" --all
166 fi
167
168 # ─── Step 2: Start HTTP server with Range support ───────────────────────────
169
170 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Starting HTTP server with Range support..."
171
172 PORT_FILE="${WORK_DIR}/port"
173
174 pythoscip-shell system . . python3.n3scip-shell system . . python3. "${SCRIPT_DIR}/range_http_server.py" \
175 "${SERVE_DIR}" "${HTTP_PORT}" "${PORT_FILE}" &
176 HTTP_PID=$!
177
178 # Wait for port file to appear
179 for i in $(seqscip-shell system . . seq. 1 10); do
180 if [[ -f "${PORT_FILE}" ]]; then
181 break
182 fi
183 sleepscip-shell system . . sleep. 0.5
184 done
185
186 if [[ ! -f "${PORT_FILE}" ]]; then
187 log_errorscip-shell shell shell-project 0.0.0 log_error(). "HTTP server did not write port file."
188 exit 1
189 fi
190
191 ACTUAL_PORT="$(catscip-shell system . . cat. "${PORT_FILE}")"
192
193 if [[ -z "${ACTUAL_PORT}" ]]; then
194 log_errorscip-shell shell shell-project 0.0.0 log_error(). "Could not determine HTTP server port."
195 exit 1
196 fi
197
198 log_infoscip-shell shell shell-project 0.0.0 log_info(). "HTTP server running on port ${ACTUAL_PORT} (PID: ${HTTP_PID})"
199
200 # Verify server is responding
201 if ! curlscip-shell system . . curl. -sf "http://127.0.0.1:${ACTUAL_PORT}/" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
202 log_errorscip-shell shell shell-project 0.0.0 log_error(). "HTTP server is not responding."
203 exit 1
204 fi
205
206 # Verify Range support works
207 TEST_FILE="simple.txt"
208 if [[ "${MODE}" == "long" ]]; then
209 TEST_FILE="large_1g.bin"
210 fi
211 RANGE_TEST=$(curlscip-shell system . . curl. -sf -r 0-3 "http://127.0.0.1:${ACTUAL_PORT}/${TEST_FILE}" \
212 -w "%{http_code}" -o /dev/null 2>/dev/null)
213 if [[ "${RANGE_TEST}" == "206" ]]; then
214 log_infoscip-shell shell shell-project 0.0.0 log_info(). "HTTP server supports Range requests (206 Partial Content)."
215 else
216 log_warnscip-shell shell shell-project 0.0.0 log_warn(). "Range request returned HTTP ${RANGE_TEST} (expected 206)."
217 fi
218
219 BASE_URL="http://127.0.0.1:${ACTUAL_PORT}/"
220
221 if [[ "${MODE}" != "long" ]]; then
222 # ─── Step 3: Mount with httpdirfs (non-cache mode) ─────────────────────────
223
224 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Mounting with httpdirfs (non-cache mode)..."
225
226 "${HTTPDIRFS_BIN}" \
227 -f \
228 "${BASE_URL}" \
229 "${MOUNT_DIR}" &
230 HTTPDIRFS_PID=$!
231
232 # Wait for the mount to become available
233 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
234 if mountpointscip-shell system . . mountpoint. -q "${MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
235 break
236 fi
237 sleepscip-shell system . . sleep. 1
238 done
239
240 if ! mountpointscip-shell system . . mountpoint. -q "${MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
241 log_errorscip-shell shell shell-project 0.0.0 log_error(). "httpdirfs failed to mount within ${MOUNT_TIMEOUT} seconds."
242 # Try to see if the process is still alive
243 if ! killscip-shell system . . kill. -0 "${HTTPDIRFS_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
244 log_errorscip-shell shell shell-project 0.0.0 log_error(). "httpdirfs process has exited."
245 fi
246 exit 1
247 fi
248
249 log_infoscip-shell shell shell-project 0.0.0 log_info(). "httpdirfs mounted successfully at ${MOUNT_DIR}"
250
251 # ─── Step 4: Run basic tests ────────────────────────────────────────────────
252
253 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Running integration tests..."
254
255 # Load the manifest
256 MANIFEST="${SERVE_DIR}/manifest.json"
257
258 # Generate a test plan from the manifest — one line per file with
259 # tab-separated fields: filename, size, sha256
260 TEST_PLAN="${WORK_DIR}/test_plan.tsv"
261 python3scip-shell system . . python3. -c "
262 import json
263 with open('${MANIFEST}') as f:
264 m = json.load(f)
265 for name in sorted(m.keys()):
266 size = m[name]['size']
267 sha = m[name]['sha256']
268 print(f'{name}\t{size}\t{sha}')
269 " > "${TEST_PLAN}"
270
271 # 4a. Test: Directory listing contains expected files
272 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Directory listing"
273
274 while IFS=$'\t' read -r filename expected_size expected_sha256; do
275 target="${MOUNT_DIR}/${filename}"
276
277 if [[ -e "${target}" ]]; then
278 passscip-shell shell shell-project 0.0.0 pass(). "File exists: ${filename}"
279 else
280 failscip-shell shell shell-project 0.0.0 fail(). "File missing: ${filename}"
281 fi
282 done < "${TEST_PLAN}"
283
284 # 4b. Test: File sizes match
285 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: File sizes"
286
287 while IFS=$'\t' read -r filename expected_size expected_sha256; do
288 target="${MOUNT_DIR}/${filename}"
289 if [[ ! -e "${target}" ]]; then
290 skipscip-shell shell shell-project 0.0.0 skip(). "Size check (file missing): ${filename}"
291 continue
292 fi
293
294 actual_size=$(statscip-shell system . . stat. -c%s "${target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || echoscip-shell system . . echo. "-1")
295 if [[ "${actual_size}" == "${expected_size}" ]]; then
296 passscip-shell shell shell-project 0.0.0 pass(). "Size correct: ${filename} (${actual_size} bytes)"
297 else
298 failscip-shell shell shell-project 0.0.0 fail(). "Size mismatch: ${filename} (expected=${expected_size}, actual=${actual_size})"
299 fi
300 done < "${TEST_PLAN}"
301
302 # 4c. Test: Content integrity (SHA-256 checksums)
303 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Content integrity (SHA-256)"
304
305 while IFS=$'\t' read -r filename expected_size expected_sha256; do
306 target="${MOUNT_DIR}/${filename}"
307 if [[ ! -e "${target}" ]]; then
308 skipscip-shell shell shell-project 0.0.0 skip(). "Checksum (file missing): ${filename}"
309 continue
310 fi
311
312 actual_sha256=$(sha256sumscip-shell system . . sha256sum. "${target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print $1}')
313 if [[ "${actual_sha256}" == "${expected_sha256}" ]]; then
314 passscip-shell shell shell-project 0.0.0 pass(). "Checksum OK: ${filename}"
315 else
316 failscip-shell shell shell-project 0.0.0 fail(). "Checksum mismatch: ${filename}"
317 log_errorscip-shell shell shell-project 0.0.0 log_error(). " expected: ${expected_sha256}"
318 log_errorscip-shell shell shell-project 0.0.0 log_error(). " actual: ${actual_sha256}"
319 fi
320 done < "${TEST_PLAN}"
321
322 # 4d. Test: Read the empty file specifically
323 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Edge cases"
324
325 EMPTY_FILE="${MOUNT_DIR}/empty_file.txt"
326 if [[ -e "${EMPTY_FILE}" ]]; then
327 content=$(catscip-shell system . . cat. "${EMPTY_FILE}")
328 if [[ -z "${content}" ]]; then
329 passscip-shell shell shell-project 0.0.0 pass(). "Empty file reads as empty"
330 else
331 failscip-shell shell shell-project 0.0.0 fail(). "Empty file has unexpected content"
332 fi
333 else
334 skipscip-shell shell shell-project 0.0.0 skip(). "Empty file not found"
335 fi
336
337 # 4e. Test: Tiny file (1 byte)
338 TINY_FILE="${MOUNT_DIR}/tiny.txt"
339 if [[ -e "${TINY_FILE}" ]]; then
340 tiny_size=$(statscip-shell system . . stat. -c%s "${TINY_FILE}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || echoscip-shell system . . echo. "-1")
341 if [[ "${tiny_size}" == "1" ]]; then
342 passscip-shell shell shell-project 0.0.0 pass(). "Tiny file has correct size (1 byte)"
343 else
344 failscip-shell shell shell-project 0.0.0 fail(). "Tiny file size mismatch (expected=1, actual=${tiny_size})"
345 fi
346 else
347 skipscip-shell shell shell-project 0.0.0 skip(). "Tiny file not found"
348 fi
349
350 # 4f-extra. Test: Zero-length files with varied special-character names
351 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Zero-length files (varied names)"
352
353 # Build the list from the manifest: all files whose size is 0
354 ZERO_FILES_LIST=$(python3scip-shell system . . python3. -c "
355 import json
356 with open('${MANIFEST}') as f:
357 m = json.load(f)
358 for name, info in sorted(m.items()):
359 if info['size'] == 0:
360 print(name)
361 ")
362
363 ZERO_FILE_COUNT=0
364 while IFS= read -r zf_name; do
365 [[ -z "${zf_name}" ]] && continue
366 ZERO_FILE_COUNT=$((ZERO_FILE_COUNT + 1))
367 target="${MOUNT_DIR}/${zf_name}"
368
369 # Existence
370 if [[ ! -e "${target}" ]]; then
371 failscip-shell shell shell-project 0.0.0 fail(). "Zero-length file missing: ${zf_name}"
372 continue
373 fi
374
375 # Size must be 0
376 zf_size=$(statscip-shell system . . stat. -c%s "${target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || echoscip-shell system . . echo. "-1")
377 if [[ "${zf_size}" == "0" ]]; then
378 passscip-shell shell shell-project 0.0.0 pass(). "Zero-length size correct: ${zf_name}"
379 else
380 failscip-shell shell shell-project 0.0.0 fail(). "Zero-length size wrong (got ${zf_size}): ${zf_name}"
381 fi
382
383 # Reading must yield empty content (no hang, no error)
384 zf_content=$(catscip-shell system . . cat. "${target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)
385 if [[ -z "${zf_content}" ]]; then
386 passscip-shell shell shell-project 0.0.0 pass(). "Zero-length content empty: ${zf_name}"
387 else
388 failscip-shell shell shell-project 0.0.0 fail(). "Zero-length file has unexpected content: ${zf_name}"
389 fi
390
391 # SHA-256 of an empty file is the well-known constant
392 EMPTY_SHA256="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
393 zf_sha=$(sha256sumscip-shell system . . sha256sum. "${target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print $1}')
394 if [[ "${zf_sha}" == "${EMPTY_SHA256}" ]]; then
395 passscip-shell shell shell-project 0.0.0 pass(). "Zero-length checksum OK: ${zf_name}"
396 else
397 failscip-shell shell shell-project 0.0.0 fail(). "Zero-length checksum mismatch: ${zf_name} (got ${zf_sha})"
398 fi
399 done <<< "${ZERO_FILES_LIST}"
400
401 if [[ "${ZERO_FILE_COUNT}" -eq 0 ]]; then
402 skipscip-shell shell shell-project 0.0.0 skip(). "No zero-length files found in manifest"
403 else
404 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Tested ${ZERO_FILE_COUNT} zero-length file(s)."
405 fi
406
407 # 4f. Test: Subdirectory is readable
408 SUBDIR="${MOUNT_DIR}/subdir with spaces"
409 if [[ -d "${SUBDIR}" ]]; then
410 passscip-shell shell shell-project 0.0.0 pass(). "Subdirectory with spaces is accessible"
411 subdir_count=$(lsscip-shell system . . ls. -1 "${SUBDIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | wcscip-shell system . . wc. -l)
412 if [[ "${subdir_count}" -ge 2 ]]; then
413 passscip-shell shell shell-project 0.0.0 pass(). "Subdirectory contains expected files (${subdir_count} entries)"
414 else
415 failscip-shell shell shell-project 0.0.0 fail(). "Subdirectory has unexpected entry count: ${subdir_count}"
416 fi
417 else
418 skipscip-shell shell shell-project 0.0.0 skip(). "Subdirectory with spaces not found"
419 fi
420
421 # 4g. Test: Read-only enforcement
422 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Read-only enforcement"
423
424 if touchscip-shell system . . touch. "${MOUNT_DIR}/should_not_exist.txt" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
425 failscip-shell shell shell-project 0.0.0 fail(). "Write should have been rejected (read-only filesystem)"
426 rmscip-shell system . . rm. -f "${MOUNT_DIR}/should_not_exist.txt" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
427 else
428 passscip-shell shell shell-project 0.0.0 pass(). "Write correctly rejected (read-only filesystem)"
429 fi
430
431 # 4h. Test: Duplicated URL deduplication
432 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Duplicated URL deduplication"
433
434 # Count the occurrences of 'simple.txt' in the mounted directory listing
435 simple_count=$(lsscip-shell system . . ls. -1 "${MOUNT_DIR}" | grepscip-shell system . . grep. -Fxc "simple.txt" || truescip-shell system . . true.)
436 if [[ "${simple_count}" -eq 1 ]]; then
437 passscip-shell shell shell-project 0.0.0 pass(). "Duplicate 'simple.txt' links successfully deduplicated (count: 1)"
438 else
439 failscip-shell shell shell-project 0.0.0 fail(). "Deduplication failed for 'simple.txt' (count: ${simple_count})"
440 fi
441
442 # Count the occurrences of 'subdir with spaces' in the mounted directory listing
443 subdir_count_dup=$(lsscip-shell system . . ls. -1 "${MOUNT_DIR}" | grepscip-shell system . . grep. -Fxc "subdir with spaces" || truescip-shell system . . true.)
444 if [[ "${subdir_count_dup}" -eq 1 ]]; then
445 passscip-shell shell shell-project 0.0.0 pass(). "Duplicate 'subdir with spaces' links successfully deduplicated (count: 1)"
446 else
447 failscip-shell shell shell-project 0.0.0 fail(). "Deduplication failed for 'subdir with spaces' (count: ${subdir_count_dup})"
448 fi
449
450
451 # ─── Step 5: Unmount non-cache mount ────────────────────────────────────────
452
453 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Unmounting non-cache mount..."
454 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${MOUNT_DIR}"
455 wait "${HTTPDIRFS_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
456 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Unmounted successfully."
457 fi
458
459 # ─── Step 5b: External-links tests ─────────────────────────────────────────
460
461 if [[ "${MODE}" != "long" ]]; then
462 log_infoscip-shell shell shell-project 0.0.0 log_info(). "=== External-links tests ==="
463
464 # Create the external server's root directory inside WORK_DIR
465 EXT_SERVE_DIR="${WORK_DIR}/ext_serve"
466 EXT_MOUNT_DIR="${WORK_DIR}/ext_mnt"
467 EXT_PORT_FILE="${WORK_DIR}/ext_port"
468 mkdirscip-shell system . . mkdir. -p "${EXT_SERVE_DIR}/external_subdir" "${EXT_MOUNT_DIR}"
469
470 # Create test files on the external server
471 EXT_FILE_CONTENT="Hello from the external server"
472 echoscip-shell system . . echo. -n "${EXT_FILE_CONTENT}" > "${EXT_SERVE_DIR}/external_file.txt"
473 EXT_FILE_SHA=$(echoscip-shell system . . echo. -n "${EXT_FILE_CONTENT}" | sha256sumscip-shell system . . sha256sum. | awkscip-shell system . . awk. '{print $1}')
474
475 # 1 MB file for content integrity verification
476 ddscip-shell system . . dd. if=/dscip-shell filesystem . . `/dev/urandom`.ev/urandomscip-shell filesystem . . `/dev/urandom`. bs=1M count=1 \
477 of="${EXT_SERVE_DIR}/external_large.bin" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
478 EXT_LARGE_SHA=$(sha256sumscip-shell system . . sha256sum. "${EXT_SERVE_DIR}/external_large.bin" \
479 | awk '{print $1}')
480
481 # File in external subdirectory
482 echoscip-shell system . . echo. -n "nested content" > "${EXT_SERVE_DIR}/external_subdir/nested_file.txt"
483 NESTED_SHA=$(echoscip-shell system . . echo. -n "nested content" | sha256sumscip-shell system . . sha256sum. | awkscip-shell system . . awk. '{print $1}')
484
485 # Two files with the same name on different paths (dedup test)
486 echoscip-shell system . . echo. -n "first duplicate" > "${EXT_SERVE_DIR}/duplicate.txt"
487 DUP_SHA=$(echoscip-shell system . . echo. -n "first duplicate" | sha256sumscip-shell system . . sha256sum. | awkscip-shell system . . awk. '{print $1}')
488 mkdirscip-shell system . . mkdir. -p "${EXT_SERVE_DIR}/other"
489 echoscip-shell system . . echo. -n "second duplicate" > "${EXT_SERVE_DIR}/other/duplicate.txt"
490
491 # Start the external HTTP server
492 pythoscip-shell system . . python3.n3scip-shell system . . python3. "${SCRIPT_DIR}/range_http_server.py" \
493 "${EXT_SERVE_DIR}" 0 "${EXT_PORT_FILE}" &
494 EXT_HTTP_PID=$!
495
496 # Register for cleanup
497 cleanup_extscip-shell shell shell-project 0.0.0 cleanup_ext().() {
498 # Unmount any FUSE mounts still attached to the external server
499 # before killing it, to avoid in-flight request aborts.
500 if [[ -d "${EXT_MOUNT_DIR}" ]] \
501 && mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
502 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${EXT_MOUNT_DIR}"
503 sleepscip-shell system . . sleep. 1
504 fi
505 if [[ -n "${EXT_HTTP_PID:-}" ]] \
506 && killscip-shell system . . kill. -0 "${EXT_HTTP_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
507 killscip-shell system . . kill. "${EXT_HTTP_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
508 wait "${EXT_HTTP_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
509 fi
510 }
511 trap 'cleanup_ext; cleanup' EXIT
512
513 # Wait for the external server port file
514 for i in $(seqscip-shell system . . seq. 1 10); do
515 [[ -f "${EXT_PORT_FILE}" ]] && break
516 sleepscip-shell system . . sleep. 0.5
517 done
518 if [[ ! -f "${EXT_PORT_FILE}" ]]; then
519 log_errorscip-shell shell shell-project 0.0.0 log_error(). "External HTTP server did not write port file."
520 exit 1
521 fi
522
523 EXT_PORT="$(catscip-shell system . . cat. "${EXT_PORT_FILE}")"
524 log_infoscip-shell shell shell-project 0.0.0 log_info(). "External HTTP server on port ${EXT_PORT} (PID: ${EXT_HTTP_PID})"
525 EXT_BASE_URL="http://127.0.0.1:${EXT_PORT}"
526
527 # Add a local file on the primary server for baseline comparison
528 echoscip-shell system . . echo. -n "local content" > "${SERVE_DIR}/local_ext_test.txt"
529 LOCAL_SHA=$(echoscip-shell system . . echo. -n "local content" | sha256sumscip-shell system . . sha256sum. | awkscip-shell system . . awk. '{print $1}')
530
531 # Write the mixed-link index.html into the primary server directory.
532 # The primary server's SimpleHTTPRequestHandler will serve both the
533 # auto-generated listing AND this custom index.html. We place it
534 # directly in SERVE_DIR so it is available alongside the real files.
535 # NOTE: httpdirfs fetches the root URL and parses whatever HTML it gets
536 # back; Python's http.server serves the auto-generated directory listing,
537 # not index.html. We therefore create a dedicated subdirectory on Server A
538 # that contains ONLY the hand-crafted index.html, so httpdirfs parses
539 # our known HTML rather than the auto-generated listing.
540 EXT_TEST_DIR="${SERVE_DIR}/ext_test_dir"
541 mkdirscip-shell system . . mkdir. -p "${EXT_TEST_DIR}"
542 echoscip-shell system . . echo. -n "local content" > "${EXT_TEST_DIR}/local_ext_test.txt"
543
544 catscip-shell system . . cat. > "${EXT_TEST_DIR}/index.html" <<HTML
545 <!DOCTYPE html>
546 <html>
547 <body>
548 <a href="local_ext_test.txt">local_ext_test.txt</a>
549 <a href="${EXT_BASE_URL}/external_file.txt">external_file.txt</a>
550 <a href="${EXT_BASE_URL}/external_large.bin">external_large.bin</a>
551 <a href="${EXT_BASE_URL}/external_subdir/">external_subdir</a>
552 <a href="${EXT_BASE_URL}/duplicate.txt">duplicate.txt</a>
553 <a href="${EXT_BASE_URL}/other/duplicate.txt">duplicate.txt</a>
554 </body>
555 </html>
556 HTML
557
558 EXT_TEST_URL="${BASE_URL}ext_test_dir/"
559
560 # ── Test 1: file listing with --external-links ─────────────────────────────
561 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: External-links file listing"
562
563 "${HTTPDIRFS_BIN}" \
564 -f \
565 --external-links \
566 "${EXT_TEST_URL}" \
567 "${EXT_MOUNT_DIR}" &
568 EXT_HTTPDIRFS_PID=$!
569
570 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
571 mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. && break
572 sleepscip-shell system . . sleep. 1
573 done
574 if ! mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
575 failscip-shell shell shell-project 0.0.0 fail(). "httpdirfs (--external-links) failed to mount."
576 killscip-shell system . . kill. "${EXT_HTTPDIRFS_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
577 else
578 # local file is present
579 if [[ -e "${EXT_MOUNT_DIR}/local_ext_test.txt" ]]; then
580 passscip-shell shell shell-project 0.0.0 pass(). "external_link_file_listing: local file present"
581 else
582 failscip-shell shell shell-project 0.0.0 fail(). "external_link_file_listing: local file missing"
583 fi
584
585 # external files appear in listing
586 if [[ -e "${EXT_MOUNT_DIR}/external_file.txt" ]]; then
587 passscip-shell shell shell-project 0.0.0 pass(). "external_link_file_listing: external_file.txt present"
588 else
589 failscip-shell shell shell-project 0.0.0 fail(). "external_link_file_listing: external_file.txt missing"
590 fi
591
592 if [[ -e "${EXT_MOUNT_DIR}/external_large.bin" ]]; then
593 passscip-shell shell shell-project 0.0.0 pass(). "external_link_file_listing: external_large.bin present"
594 else
595 failscip-shell shell shell-project 0.0.0 fail(). "external_link_file_listing: external_large.bin missing"
596 fi
597
598 # ── Test 2: content integrity ───────────────────────────────────────────
599 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: External-links content integrity"
600
601 if [[ -e "${EXT_MOUNT_DIR}/external_file.txt" ]]; then
602 actual=$(sha256sumscip-shell system . . sha256sum. "${EXT_MOUNT_DIR}/external_file.txt" \
603 | awk '{print $1}')
604 if [[ "${actual}" == "${EXT_FILE_SHA}" ]]; then
605 passscip-shell shell shell-project 0.0.0 pass(). "external_link_content_integrity: external_file.txt OK"
606 else
607 failscip-shell shell shell-project 0.0.0 fail(). "external_link_content_integrity: external_file.txt checksum mismatch"
608 fi
609 else
610 skipscip-shell shell shell-project 0.0.0 skip(). "external_link_content_integrity: external_file.txt missing"
611 fi
612
613 if [[ -e "${EXT_MOUNT_DIR}/external_large.bin" ]]; then
614 actual=$(sha256sumscip-shell system . . sha256sum. "${EXT_MOUNT_DIR}/external_large.bin" \
615 | awk '{print $1}')
616 if [[ "${actual}" == "${EXT_LARGE_SHA}" ]]; then
617 passscip-shell shell shell-project 0.0.0 pass(). "external_link_content_integrity: external_large.bin OK"
618 else
619 failscip-shell shell shell-project 0.0.0 fail(). "external_link_content_integrity: external_large.bin checksum mismatch"
620 fi
621 else
622 skipscip-shell shell shell-project 0.0.0 skip(). "external_link_content_integrity: external_large.bin missing"
623 fi
624
625 # ── Test 4: external directory ──────────────────────────────────────────
626 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: External-links directory traversal"
627
628 if [[ -d "${EXT_MOUNT_DIR}/external_subdir" ]]; then
629 passscip-shell shell shell-project 0.0.0 pass(). "external_link_directory: external_subdir is a directory"
630 if [[ -e "${EXT_MOUNT_DIR}/external_subdir/nested_file.txt" ]]; then
631 passscip-shell shell shell-project 0.0.0 pass(). "external_link_directory: nested_file.txt present"
632 nested_sha=$(sha256sumscip-shell system . . sha256sum. \
633 "${EXT_MOUNT_DIR}/external_subdir/nested_file.txt" \
634 | awk '{print $1}')
635 if [[ "${nested_sha}" == "${NESTED_SHA}" ]]; then
636 passscip-shell shell shell-project 0.0.0 pass(). "external_link_directory: nested_file.txt content OK"
637 else
638 failscip-shell shell shell-project 0.0.0 fail(). "external_link_directory: nested_file.txt checksum mismatch"
639 fi
640 else
641 failscip-shell shell shell-project 0.0.0 fail(). "external_link_directory: nested_file.txt missing"
642 fi
643 else
644 failscip-shell shell shell-project 0.0.0 fail(). "external_link_directory: external_subdir not a directory"
645 fi
646
647 # ── Test 5: first-wins dedup ────────────────────────────────────────────
648 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: External-links first-wins deduplication"
649
650 dup_count=$(lsscip-shell system . . ls. -1 "${EXT_MOUNT_DIR}" | grepscip-shell system . . grep. -c "^duplicate\.txt$" || truescip-shell system . . true.)
651 if [[ "${dup_count}" -eq 1 ]]; then
652 passscip-shell shell shell-project 0.0.0 pass(). "external_link_dedup_first_wins: exactly one duplicate.txt"
653 dup_sha=$(sha256sumscip-shell system . . sha256sum. "${EXT_MOUNT_DIR}/duplicate.txt" \
654 | awk '{print $1}')
655 if [[ "${dup_sha}" == "${DUP_SHA}" ]]; then
656 passscip-shell shell shell-project 0.0.0 pass(). "external_link_dedup_first_wins: first duplicate wins"
657 else
658 failscip-shell shell shell-project 0.0.0 fail(). "external_link_dedup_first_wins: wrong duplicate content"
659 fi
660 else
661 failscip-shell shell shell-project 0.0.0 fail(). "external_link_dedup_first_wins: expected 1 duplicate.txt, got ${dup_count}"
662 fi
663
664 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${EXT_MOUNT_DIR}"
665 wait "${EXT_HTTPDIRFS_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
666 fi
667
668 # ── Test 3: backward compatibility (no --external-links) ───────────────────
669 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: External-links backward compatibility"
670
671 "${HTTPDIRFS_BIN}" \
672 -f \
673 "${EXT_TEST_URL}" \
674 "${EXT_MOUNT_DIR}" &
675 COMPAT_PID=$!
676
677 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
678 mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. && break
679 sleepscip-shell system . . sleep. 1
680 done
681 if ! mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
682 failscip-shell shell shell-project 0.0.0 fail(). "httpdirfs (no --external-links) failed to mount."
683 killscip-shell system . . kill. "${COMPAT_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
684 else
685 if [[ ! -e "${EXT_MOUNT_DIR}/external_file.txt" ]]; then
686 passscip-shell shell shell-project 0.0.0 pass(). "external_link_backward_compat: external_file.txt not present (correct)"
687 else
688 failscip-shell shell shell-project 0.0.0 fail(). "external_link_backward_compat: external_file.txt unexpectedly present"
689 fi
690
691 if [[ -e "${EXT_MOUNT_DIR}/local_ext_test.txt" ]]; then
692 passscip-shell shell shell-project 0.0.0 pass(). "external_link_backward_compat: local_ext_test.txt still present"
693 else
694 failscip-shell shell shell-project 0.0.0 fail(). "external_link_backward_compat: local_ext_test.txt missing"
695 fi
696
697 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${EXT_MOUNT_DIR}"
698 wait "${COMPAT_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
699 fi
700
701 # ── Test 6: cache mode with --external-links ───────────────────────────────
702 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: External-links cache mode"
703
704 # Remove and recreate the cache directory for a completely clean state
705 rmscip-shell system . . rm. -rf "${CACHE_DIR:?}"
706 mkdirscip-shell system . . mkdir. -p "${CACHE_DIR}"
707
708 "${HTTPDIRFS_BIN}" \
709 -f \
710 --external-links \
711 --cache \
712 --cache-location "${CACHE_DIR}" \
713 "${EXT_TEST_URL}" \
714 "${EXT_MOUNT_DIR}" &
715 EXT_CACHE_PID=$!
716
717 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
718 mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. && break
719 sleepscip-shell system . . sleep. 1
720 done
721
722 if ! mountpointscip-shell system . . mountpoint. -q "${EXT_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
723 failscip-shell shell shell-project 0.0.0 fail(). "httpdirfs (--external-links --cache) failed to mount."
724 killscip-shell system . . kill. "${EXT_CACHE_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
725 else
726 # 6a. Check file presence
727 if [[ -e "${EXT_MOUNT_DIR}/external_file.txt" ]]; then
728 passscip-shell shell shell-project 0.0.0 pass(). "external_link_cache_mode: file present"
729 else
730 failscip-shell shell shell-project 0.0.0 fail(). "external_link_cache_mode: file missing"
731 fi
732
733 # 6b. Verify content integrity (downloads and caches the file)
734 if [[ -e "${EXT_MOUNT_DIR}/external_file.txt" ]]; then
735 actual=$(sha256sumscip-shell system . . sha256sum. "${EXT_MOUNT_DIR}/external_file.txt" \
736 | awk '{print $1}')
737 if [[ "${actual}" == "${EXT_FILE_SHA}" ]]; then
738 passscip-shell shell shell-project 0.0.0 pass(). "external_link_cache_mode: content OK"
739 else
740 failscip-shell shell shell-project 0.0.0 fail(). "external_link_cache_mode: content checksum mismatch"
741 fi
742 else
743 skipscip-shell shell shell-project 0.0.0 skip(). "external_link_cache_mode: content check skipped (file missing)"
744 fi
745
746 # 6c. Verify re-reading from cache works
747 if [[ -e "${EXT_MOUNT_DIR}/external_file.txt" ]]; then
748 actual_cached=$(sha256sumscip-shell system . . sha256sum. "${EXT_MOUNT_DIR}/external_file.txt" \
749 | awk '{print $1}')
750 if [[ "${actual_cached}" == "${EXT_FILE_SHA}" ]]; then
751 passscip-shell shell shell-project 0.0.0 pass(). "external_link_cache_mode: cached re-read OK"
752 else
753 failscip-shell shell shell-project 0.0.0 fail(). "external_link_cache_mode: cached re-read checksum mismatch"
754 fi
755 fi
756
757 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${EXT_MOUNT_DIR}"
758 wait "${EXT_CACHE_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
759 fi
760
761 # Stop the external HTTP server
762 cleanup_extscip-shell shell shell-project 0.0.0 cleanup_ext().
763 log_infoscip-shell shell shell-project 0.0.0 log_info(). "External HTTP server stopped."
764
765 # ── Test 7: Cache size thresholds ───────────────────────────────────────────
766 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Cache size thresholds"
767
768 # --- Test 7a: cache-min-size threshold ---
769 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Subgroup: Cache minimum size threshold"
770 rmscip-shell system . . rm. -rf "${CACHE_DIR:?}"
771 mkdirscip-shell system . . mkdir. -p "${CACHE_DIR}"
772
773 "${HTTPDIRFS_BIN}" \
774 -f \
775 --cache \
776 --cache-location "${CACHE_DIR}" \
777 --cache-min-size 1024 \
778 "${BASE_URL}" \
779 "${CACHE_MOUNT_DIR}" &
780 THRESH_PID=$!
781
782 # Wait for mount
783 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
784 if mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
785 break
786 fi
787 sleepscip-shell system . . sleep. 1
788 done
789
790 if ! mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
791 failscip-shell shell shell-project 0.0.0 fail(). "httpdirfs (cache-min-size) failed to mount."
792 killscip-shell system . . kill. "${THRESH_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
793 else
794 # Read tiny.txt (1 byte, should not be cached)
795 tiny_content=$(catscip-shell system . . cat. "${CACHE_MOUNT_DIR}/tiny.txt")
796 if [[ -n "${tiny_content}" ]]; then
797 passscip-shell shell shell-project 0.0.0 pass(). "cache-min-size: tiny.txt read successfully"
798 else
799 failscip-shell shell shell-project 0.0.0 fail(). "cache-min-size: tiny.txt read failed"
800 fi
801
802 # Read simple.txt (should be cached as it is > 1024 bytes)
803 catscip-shell system . . cat. "${CACHE_MOUNT_DIR}/simple.txt" > /dev/nullscip-shell filesystem . . `/dev/null`.
804
805 # Check cache directory
806 # tiny.txt should NOT have a cache file
807 tiny_cache_file=$(findscip-shell system . . find. "${CACHE_DIR}/meta" -type f -name "*tiny.txt" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -n 1 || truescip-shell system . . true.)
808 if [[ -z "${tiny_cache_file}" ]]; then
809 passscip-shell shell shell-project 0.0.0 pass(). "cache-min-size: tiny.txt (1 byte) was NOT cached (correct)"
810 else
811 failscip-shell shell shell-project 0.0.0 fail(). "cache-min-size: tiny.txt (1 byte) was unexpectedly cached"
812 fi
813
814 # simple.txt should have a cache file
815 simple_cache_file=$(findscip-shell system . . find. "${CACHE_DIR}/meta" -type f -name "*simple.txt" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -n 1 || truescip-shell system . . true.)
816 if [[ -n "${simple_cache_file}" ]]; then
817 passscip-shell shell shell-project 0.0.0 pass(). "cache-min-size: simple.txt was cached (correct)"
818 else
819 failscip-shell shell shell-project 0.0.0 fail(). "cache-min-size: simple.txt was NOT cached"
820 fi
821
822 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${CACHE_MOUNT_DIR}"
823 wait "${THRESH_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
824 fi
825
826 # --- Test 7b: cache-max-size threshold ---
827 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Subgroup: Cache maximum size threshold"
828 rmscip-shell system . . rm. -rf "${CACHE_DIR:?}"
829 mkdirscip-shell system . . mkdir. -p "${CACHE_DIR}"
830
831 # We set max size to 100 bytes. tiny.txt (1 byte) is cached, simple.txt (> 1024 bytes) is not.
832 "${HTTPDIRFS_BIN}" \
833 -f \
834 --cache \
835 --cache-location "${CACHE_DIR}" \
836 --cache-max-size 100 \
837 "${BASE_URL}" \
838 "${CACHE_MOUNT_DIR}" &
839 THRESH_PID=$!
840
841 # Wait for mount
842 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
843 if mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
844 break
845 fi
846 sleepscip-shell system . . sleep. 1
847 done
848
849 if ! mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
850 failscip-shell shell shell-project 0.0.0 fail(). "cache-max-size: httpdirfs failed to mount"
851 killscip-shell system . . kill. "${THRESH_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
852 else
853 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Subgroup: Test cache-max-size (max size=100)"
854
855 # Read tiny.txt (should be cached)
856 catscip-shell system . . cat. "${CACHE_MOUNT_DIR}/tiny.txt" > /dev/nullscip-shell filesystem . . `/dev/null`.
857
858 # Read simple.txt (should not be cached)
859 catscip-shell system . . cat. "${CACHE_MOUNT_DIR}/simple.txt" > /dev/nullscip-shell filesystem . . `/dev/null`.
860
861 # Check cache directory
862 # tiny.txt should have a cache file
863 tiny_cache_file=$(findscip-shell system . . find. "${CACHE_DIR}/meta" -type f -name "*tiny.txt" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -n 1 || truescip-shell system . . true.)
864 if [[ -n "${tiny_cache_file}" ]]; then
865 passscip-shell shell shell-project 0.0.0 pass(). "cache-max-size: tiny.txt (1 byte) was cached (correct)"
866 else
867 failscip-shell shell shell-project 0.0.0 fail(). "cache-max-size: tiny.txt (1 byte) was NOT cached"
868 fi
869
870 # simple.txt should NOT have a cache file
871 simple_cache_file=$(findscip-shell system . . find. "${CACHE_DIR}/meta" -type f -name "*simple.txt" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -n 1 || truescip-shell system . . true.)
872 if [[ -z "${simple_cache_file}" ]]; then
873 passscip-shell shell shell-project 0.0.0 pass(). "cache-max-size: simple.txt (>100 bytes) was NOT cached (correct)"
874 else
875 failscip-shell shell shell-project 0.0.0 fail(). "cache-max-size: simple.txt (>100 bytes) was unexpectedly cached"
876 fi
877
878 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${CACHE_MOUNT_DIR}"
879 wait "${THRESH_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
880 fi
881
882 # --- Test 7c: cache size invalid and inconsistent parameter checks ---
883 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Subgroup: Cache size threshold invalid parameter validation"
884
885 # Test negative cache-min-size
886 err_out=$("${HTTPDIRFS_BIN}" --cache --cache-min-size -50 "${BASE_URL}" "${CACHE_MOUNT_DIR}" 2>&1 || truescip-shell system . . true.)
887 if [[ "${err_out}" == *"Error: --cache-min-size requires a non-negative integer"* ]]; then
888 passscip-shell shell shell-project 0.0.0 pass(). "cache size validation: negative --cache-min-size rejected (correct)"
889 else
890 failscip-shell shell shell-project 0.0.0 fail(). "cache size validation: negative --cache-min-size not rejected correctly: ${err_out}"
891 fi
892
893 # Test non-numeric cache-max-size
894 err_out=$("${HTTPDIRFS_BIN}" --cache --cache-max-size abc "${BASE_URL}" "${CACHE_MOUNT_DIR}" 2>&1 || truescip-shell system . . true.)
895 if [[ "${err_out}" == *"Error: --cache-max-size requires a non-negative integer"* ]]; then
896 passscip-shell shell shell-project 0.0.0 pass(). "cache size validation: non-numeric --cache-max-size rejected (correct)"
897 else
898 failscip-shell shell shell-project 0.0.0 fail(). "cache size validation: non-numeric --cache-max-size not rejected correctly: ${err_out}"
899 fi
900
901 # Test min-size > max-size inconsistency
902 err_out=$("${HTTPDIRFS_BIN}" --cache --cache-min-size 1000 --cache-max-size 500 "${BASE_URL}" "${CACHE_MOUNT_DIR}" 2>&1 || truescip-shell system . . true.)
903 if [[ "${err_out}" == *"Error: --cache-min-size cannot be greater than --cache-max-size"* ]]; then
904 passscip-shell shell shell-project 0.0.0 pass(). "cache size validation: min > max consistency check rejected (correct)"
905 else
906 failscip-shell shell shell-project 0.0.0 fail(). "cache size validation: min > max inconsistency not rejected correctly: ${err_out}"
907 fi
908 fi
909
910 # ─── Step 6: Cache mode with multithreaded reads ────────────────────────────
911
912 if [[ "${MODE}" != "short" ]]; then
913 log_infoscip-shell shell shell-project 0.0.0 log_info(). "=== Cache mode tests ==="
914
915 # Get the large file's expected SHA-256 from the manifest
916 LARGE_FILE_SHA256=$(python3scip-shell system . . python3. -c "
917 import json
918 with open('${MANIFEST}') as f:
919 m = json.load(f)
920 entry = m.get('large_1g.bin')
921 if entry:
922 print(entry['sha256'])
923 else:
924 print('')
925 ")
926
927 if [[ -z "${LARGE_FILE_SHA256}" ]]; then
928 skipscip-shell shell shell-project 0.0.0 skip(). "Cache test: large_1g.bin not in manifest"
929 else
930 # Test with multiple block sizes to exercise segbc edge cases:
931 # 8 MB - default, 1 GB / 8 MB = 128 exactly (no remainder)
932 # 16 MB - fewer segments, 1 GB / 16 MB = 64 exactly
933 # 1 MB - many segments, 1 GB / 1 MB = 1024 exactly
934 # 7 MB - 1 GB / 7 MB ≈ 146.3 (remainder)
935 # 3 MB - 1 GB / 3 MB ≈ 341.3 (remainder)
936 BLOCK_SIZES="8 16 1 7 3"
937
938 for BLKSZ in ${BLOCK_SIZES}; do
939 log_infoscip-shell shell shell-project 0.0.0 log_info(). "--- Cache test: --dl-seg-size ${BLKSZ} ---"
940
941 # Remove and recreate the cache directory for a completely
942 # clean state — ensures no metadata from a previous block size
943 # can affect the next run
944 rmscip-shell system . . rm. -rf "${CACHE_DIR:?}"
945 mkdirscip-shell system . . mkdir. -p "${CACHE_DIR}"
946
947 "${HTTPDIRFS_BIN}" \
948 -f \
949 --cache \
950 --cache-location "${CACHE_DIR}" \
951 --dl-seg-size "${BLKSZ}" \
952 "${BASE_URL}" \
953 "${CACHE_MOUNT_DIR}" &
954 CACHE_HTTPDIRFS_PID=$!
955
956 # Wait for mount
957 for i in $(seqscip-shell system . . seq. 1 "${MOUNT_TIMEOUT}"); do
958 if mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
959 break
960 fi
961 sleepscip-shell system . . sleep. 1
962 done
963
964 if ! mountpointscip-shell system . . mountpoint. -q "${CACHE_MOUNT_DIR}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
965 log_errorscip-shell shell shell-project 0.0.0 log_error(). "httpdirfs (cache, blksz=${BLKSZ}M) failed to mount."
966 skipscip-shell shell shell-project 0.0.0 skip(). "Cache mode tests (mount failed, blksz=${BLKSZ}M)"
967 wait "${CACHE_HTTPDIRFS_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
968 continue
969 fi
970
971 log_infoscip-shell shell shell-project 0.0.0 log_info(). "httpdirfs (cache, blksz=${BLKSZ}M) mounted"
972
973 LARGE_FILE="${CACHE_MOUNT_DIR}/large_1g.bin"
974
975 # Test: Multithreaded read with 8 threads
976 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Multithreaded cache read (blksz=${BLKSZ}M)"
977 if pyscip-shell system . . python3.thon3scip-shell system . . python3. "${SCRIPT_DIR}/multithread_read.py" \
978 "${LARGE_FILE}" "${LARGE_FILE_SHA256}" 8; then
979 passscip-shell shell shell-project 0.0.0 pass(). "Multithreaded read (blksz=${BLKSZ}M, 8 threads): OK"
980 else
981 failscip-shell shell shell-project 0.0.0 fail(). "Multithreaded read (blksz=${BLKSZ}M, 8 threads): FAIL"
982 fi
983
984 # Test: Sequential re-read (should come from cache now)
985 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Cached re-read (blksz=${BLKSZ}M)"
986 actual_sha256=$(sha256sumscip-shell system . . sha256sum. "${LARGE_FILE}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. \
987 | awk '{print $1}')
988 if [[ "${actual_sha256}" == "${LARGE_FILE_SHA256}" ]]; then
989 passscip-shell shell shell-project 0.0.0 pass(). "Cached re-read (blksz=${BLKSZ}M): OK"
990 else
991 failscip-shell shell shell-project 0.0.0 fail(). "Cached re-read (blksz=${BLKSZ}M): FAIL"
992 log_errorscip-shell shell shell-project 0.0.0 log_error(). " expected: ${LARGE_FILE_SHA256}"
993 log_errorscip-shell shell shell-project 0.0.0 log_error(). " actual: ${actual_sha256}"
994 fi
995
996 # Test: Zero-length files in cache mode (run once — not block-size
997 # dependent, but checked here to confirm the fi->fh=0 bypass works
998 # when the cache system is active).
999 if [[ "${MODE}" != "long" && "${BLKSZ}" == "8" ]]; then
1000 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Test group: Zero-length files in cache mode"
1001 CACHE_ZERO_FILES_LIST=$(python3scip-shell system . . python3. -c "
1002 import json
1003 with open('${MANIFEST}') as f:
1004 m = json.load(f)
1005 for name, info in sorted(m.items()):
1006 if info['size'] == 0:
1007 print(name)
1008 ")
1009 CACHE_ZERO_COUNT=0
1010 EMPTY_SHA256="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
1011 while IFS= read -r czf_name; do
1012 [[ -z "${czf_name}" ]] && continue
1013 CACHE_ZERO_COUNT=$((CACHE_ZERO_COUNT + 1))
1014 czf_target="${CACHE_MOUNT_DIR}/${czf_name}"
1015
1016 if [[ ! -e "${czf_target}" ]]; then
1017 failscip-shell shell shell-project 0.0.0 fail(). "Cache: zero-length file missing: ${czf_name}"
1018 continue
1019 fi
1020
1021 czf_size=$(statscip-shell system . . stat. -c%s "${czf_target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || echoscip-shell system . . echo. "-1")
1022 if [[ "${czf_size}" == "0" ]]; then
1023 passscip-shell shell shell-project 0.0.0 pass(). "Cache: zero-length size correct: ${czf_name}"
1024 else
1025 failscip-shell shell shell-project 0.0.0 fail(). "Cache: zero-length size wrong (${czf_size}): ${czf_name}"
1026 fi
1027
1028 czf_content=$(catscip-shell system . . cat. "${czf_target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)
1029 if [[ -z "${czf_content}" ]]; then
1030 passscip-shell shell shell-project 0.0.0 pass(). "Cache: zero-length content empty: ${czf_name}"
1031 else
1032 failscip-shell shell shell-project 0.0.0 fail(). "Cache: zero-length has unexpected content: ${czf_name}"
1033 fi
1034
1035 czf_sha=$(sha256sumscip-shell system . . sha256sum. "${czf_target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print $1}')
1036 if [[ "${czf_sha}" == "${EMPTY_SHA256}" ]]; then
1037 passscip-shell shell shell-project 0.0.0 pass(). "Cache: zero-length checksum OK: ${czf_name}"
1038 else
1039 failscip-shell shell shell-project 0.0.0 fail(). "Cache: zero-length checksum mismatch: ${czf_name}"
1040 fi
1041 done <<< "${CACHE_ZERO_FILES_LIST}"
1042 if [[ "${CACHE_ZERO_COUNT}" -eq 0 ]]; then
1043 skipscip-shell shell shell-project 0.0.0 skip(). "Cache: no zero-length files in manifest"
1044 else
1045 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Cache: tested ${CACHE_ZERO_COUNT} zero-length file(s)."
1046 fi
1047 fi
1048
1049 # Unmount
1050 do_unmountscip-shell shell shell-project 0.0.0 do_unmount(). "${CACHE_MOUNT_DIR}"
1051 wait "${CACHE_HTTPDIRFS_PID}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
1052 log_infoscip-shell shell shell-project 0.0.0 log_info(). "Cache mount (blksz=${BLKSZ}M) unmounted."
1053
1054 done
1055 fi
1056 fi
1057
1058
1059 # ─── Summary ────────────────────────────────────────────────────────────────
1060
1061 echoscip-shell system . . echo. ""
1062 echoscip-shell system . . echo. "═══════════════════════════════════════════════"
1063 echoscip-shell system . . echo. -e " Results: ${GREEN}${PASS_COUNT} passed${NC}, ${RED}${FAIL_COUNT} failed${NC}, ${YELLOW}${SKIP_COUNT} skipped${NC}"
1064 echoscip-shell system . . echo. "═══════════════════════════════════════════════"
1065 echoscip-shell system . . echo. ""
1066
1067 if [[ "${FAIL_COUNT}" -gt 0 ]]; then
1068 log_errorscip-shell shell shell-project 0.0.0 log_error(). "Some tests FAILED."
1069 exit 1
1070 fi
1071
1072 log_infoscip-shell shell shell-project 0.0.0 log_info(). "All tests passed!"
1073 exit 0