AtlatestRepositorysigil
sigil / tree / test / integrationtest-env-channel-direct-source.sgl
1
#!/usr/bin/env sigil2
;;; Demonstration port of test-env-channel-direct-source.sh.3
;;; This is a library test, not a release gate. The Bash sibling remains4
;;; authoritative until a release containing (sigil shell) has shipped.6
(import (sigil env manifest)7
(sigil env snapshot)8
(sigil fs)9
(sigil path)10
(sigil process)11
(sigil shell)12
(sigil shell checks)13
(sigil store)14
(sigil string))16
(requires (tools minisign))18
(define repo-root19
(realpath (path-dirname (path-dirname (script-dir)))))20
(define scratch (make-temp-directory))21
(define channel (and scratch (path-join scratch "channel")))22
(define cache (and scratch (path-join scratch "cache")))23
(define registry-metadata24
(path-join repo-root "test/fixtures/registry-trust/registry.json"))25
(define source-hash #f)26
(define evaluated-environment #f)28
(define (delete-tree path)29
(when (and path (file-exists? path))30
(if (directory? path)31
(begin32
(for-each33
(lambda (entry) (delete-tree (path-join path entry)))34
(directory-list path))35
(delete-directory path))36
(delete-file path))))38
(check "SGLSH-S19-direct-source-evaluates"39
(unless scratch (error "could not create a temporary directory"))40
(let* ((packages-dir (path-join channel "src/core/packages"))41
(snapshot (path-join channel "snapshot.sgl"))42
(secret-key43
(path-join repo-root44
"test/fixtures/registry-signing-test-key/channels-test.key"))45
(toolchain-recipe (hash-data "toolchain-recipe"))46
(toolchain-output (hash-data "toolchain-output")))47
(ensure-directory packages-dir)48
(ensure-directory cache)49
(write-file-string50
(path-join packages-dir "wasm.sgl")51
(string-append52
"(define-library (core packages wasm)\n"53
" (import (sigil core) (sigil env authoring))\n"54
" (export direct-environment)\n"55
" (begin\n"56
" (define (direct-environment)\n"57
" (environment packages: '()))))\n"))58
(write-file-string59
(path-join scratch "env.sgl")60
"(import (core packages wasm))\n(direct-environment)\n")61
(set! source-hash (hash-directory (path-join channel "src")))62
(let* ((content63
(string-append64
"(snapshot-content schema: 1 id: \"direct-source\" sequence: 1)\n"65
"(toolchain id: \"toolchain/zig\" version: \"test\" recipe: \"sha256:"66
toolchain-recipe "\" output: \"sha256:" toolchain-output "\")\n"67
"(pkg id: \"core/packages/wasm\" version: \"0.1.0\" recipe: \"sha256:"68
source-hash "\")\n"))69
(content-hash (hash-data content)))70
(write-file-string71
snapshot72
(string-append73
"(snapshot schema: 1 id: \"direct-source\" sequence: 1 content-hash: \"sha256:"74
content-hash "\")\n"75
"(toolchain id: \"toolchain/zig\" version: \"test\" recipe: \"sha256:"76
toolchain-recipe "\" output: \"sha256:" toolchain-output "\")\n"77
"(pkg id: \"core/packages/wasm\" version: \"0.1.0\" recipe: \"sha256:"78
source-hash "\")\n")))79
($ minisign -S -W -s ,secret-key -m ,snapshot80
-t "registry=pkg.usesigil.org path=/v1/channels/direct-source/snapshot.sgl seq=201 ts=2026-07-28T00:01:00Z")81
(setenv! "XDG_CACHE_HOME" cache)82
;; Native bundles initialize registry trust before script top-level, so83
;; the caller must set this before starting Sigil, as the Bash gate does.84
(unless (equal? (getenv "SIGIL_REGISTRY_METADATA") registry-metadata)85
(error86
(format "run with SIGIL_REGISTRY_METADATA=~a" registry-metadata)))87
(set! evaluated-environment88
(evaluate-environment-program89
(path-join scratch "env.sgl")90
channel91
(read-verified-snapshot snapshot 0)92
(or (getenv "SIGIL") (path-join repo-root "build/dev/bin/sigil"))93
'()))))95
(check "SGLSH-S19-direct-source-manifest-contains-wasm"96
(unless (and evaluated-environment97
(pair? (cdr evaluated-environment))98
(string=? (format "~a" (car (cadr evaluated-environment)))99
"core/packages/wasm")100
(string=? (format "~a" (cadr (cadr evaluated-environment)))101
"0.1.0"))102
(error (format "manifest does not contain core/packages/wasm 0.1.0: ~a"103
evaluated-environment))))105
(check "SGLSH-S19-direct-source-hash-is-stable"106
(unless (equal? (authoring-channel-source-hash channel) source-hash)107
(error "authoring source hash diverged from hash-directory")))109
(check "SGLSH-S19-direct-source-cleans-up"110
(delete-tree scratch))112
(run-checks!)