shop audit

This commit is contained in:
2026-02-14 14:00:27 -06:00
parent e80e615634
commit 8ec56e85fa
26 changed files with 19402 additions and 19132 deletions

76
tests/build_audit.cm Normal file
View File

@@ -0,0 +1,76 @@
// Build system audit tests
// Tests deterministic dylib paths, symbol naming, and lib layout
var shop = use('internal/shop')
var runtime = use('runtime')
return {
// ========================================================================
// DETERMINISTIC DYLIB PATHS
// ========================================================================
test_dylib_path_deterministic: function() {
var path = shop.get_dylib_path('core', 'time')
if (!ends_with(path, '/lib/core/time.dylib')) return "dylib path should end with /lib/core/time.dylib, got: " + path
},
test_dylib_path_internal: function() {
var path = shop.get_dylib_path('core', 'internal/os')
if (!ends_with(path, '/lib/core/internal/os.dylib')) return "dylib path should end with /lib/core/internal/os.dylib, got: " + path
},
test_dylib_path_external_package: function() {
var path = shop.get_dylib_path('gitea.pockle.world/john/prosperon', 'sprite')
if (!ends_with(path, '/lib/gitea.pockle.world/john/prosperon/sprite.dylib'))
return "dylib path should mirror package layout, got: " + path
},
// ========================================================================
// SYMBOL NAMING
// ========================================================================
test_c_symbol_module: function() {
var sym = shop.c_symbol_for_file('pkg', 'sprite.c')
if (sym != 'js_pkg_sprite_use') return "expected js_pkg_sprite_use, got: " + sym
},
test_c_symbol_program: function() {
var sym = shop.c_symbol_for_file('pkg', 'game.ce')
if (sym != 'js_pkg_game_program') return "expected js_pkg_game_program, got: " + sym
},
test_c_symbol_internal: function() {
var sym = shop.c_symbol_for_file('pkg', 'internal/os.c')
if (sym != 'js_pkg_internal_os_use') return "expected js_pkg_internal_os_use, got: " + sym
},
test_c_symbol_dotted_package: function() {
var sym = shop.c_symbol_for_file('gitea.pockle.world/john/prosperon', 'sprite.c')
if (sym != 'js_gitea_pockle_world_john_prosperon_sprite_use')
return "expected js_gitea_pockle_world_john_prosperon_sprite_use, got: " + sym
},
// ========================================================================
// LIB NAME
// ========================================================================
test_lib_name: function() {
var name = shop.lib_name_for_package('gitea.pockle.world/john/prosperon')
if (name != 'gitea_pockle_world_john_prosperon')
return "expected gitea_pockle_world_john_prosperon, got: " + name
},
test_lib_name_simple: function() {
var name = shop.lib_name_for_package('core')
if (name != 'core') return "expected core, got: " + name
},
// ========================================================================
// SYMBOL PREFIX
// ========================================================================
test_c_symbol_prefix: function() {
var prefix = shop.c_symbol_prefix('mypackage')
if (prefix != 'js_mypackage_') return "expected js_mypackage_, got: " + prefix
}
}

85
tests/shop_audit.cm Normal file
View File

@@ -0,0 +1,85 @@
// Shop system audit tests
// Tests module resolution, caching, and runtime paths
// accessible from user code via use()
var json = use('json')
var runtime = use('runtime')
var time_mod = use('time')
return {
// ========================================================================
// MODULE RESOLUTION
// ========================================================================
test_use_core_module: function() {
if (!is_object(json)) return "use('json') should return an object"
if (!is_function(json.encode)) return "json should have encode function"
if (!is_function(json.decode)) return "json should have decode function"
},
test_use_returns_cached: function() {
var json2 = use('json')
if (json != json2) return "two use('json') calls should return same reference"
},
test_use_time_module: function() {
if (!is_object(time_mod)) return "use('time') should return an object"
},
test_use_nonexistent_disrupts: function() {
var caught = false
var _fn = function() {
var x = use('nonexistent_xyz_99')
} disruption {
caught = true
}
_fn()
if (!caught) return "use('nonexistent_xyz_99') should disrupt"
},
// ========================================================================
// RUNTIME PATHS
// ========================================================================
test_runtime_shop_path: function() {
if (is_null(runtime.shop_path)) return "runtime.shop_path should not be null"
if (!is_text(runtime.shop_path)) return "runtime.shop_path should be text"
},
test_runtime_core_path: function() {
if (is_null(runtime.core_path)) return "runtime.core_path should not be null"
if (!is_text(runtime.core_path)) return "runtime.core_path should be text"
},
test_runtime_is_frozen: function() {
if (!is_stone(runtime)) return "runtime should be frozen (stoned)"
},
// ========================================================================
// MODULE CACHING BEHAVIOR
// ========================================================================
test_json_encode_decode_roundtrip: function() {
var obj = {a: 1, b: "hello", c: [1, 2, 3]}
var encoded = json.encode(obj)
var decoded = json.decode(encoded)
if (decoded.a != 1) return "roundtrip failed for number"
if (decoded.b != "hello") return "roundtrip failed for text"
if (length(decoded.c) != 3) return "roundtrip failed for array"
},
test_use_blob_module: function() {
var b = use('blob')
if (!is_object(b)) return "use('blob') should return an object"
},
test_use_math_module: function() {
var m = use('math')
if (!is_object(m)) return "use('math') should return an object"
},
test_use_random_module: function() {
var r = use('random')
if (!is_object(r)) return "use('random') should return an object"
}
}