feat: windows-devshell
This commit is contained in:
44
test/package/windows-devshell/default.nix
Normal file
44
test/package/windows-devshell/default.nix
Normal file
@@ -0,0 +1,44 @@
|
||||
{ system, inputs, self, pkgs }:
|
||||
let
|
||||
lib = inputs.nixpkgs.lib;
|
||||
|
||||
windowsDevShellStandalone = self.packages.${system}.windows-devshell-standalone;
|
||||
|
||||
mkTest = testName: testDrv: pkgs.runCommand "windows-devshell-test-${testName}"
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep ];
|
||||
windowsDevShellStandalone = windowsDevShellStandalone;
|
||||
} ''
|
||||
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
|
||||
test=${testDrv}
|
||||
${builtins.readFile ./launch.sh}
|
||||
mkdir -p "$out"
|
||||
'';
|
||||
|
||||
testDir = builtins.readDir ./test;
|
||||
testDrvs =
|
||||
lib.mapAttrs' (n: v:
|
||||
lib.nameValuePair (lib.removeSuffix ".sh" n) v
|
||||
) (lib.filterAttrs (_: v: v != null)
|
||||
(lib.mapAttrs (n: t:
|
||||
if t == "directory" then
|
||||
pkgs.runCommand "test-${n}" {} ''
|
||||
if ! [ -f ${./test + "/${n}" + /run.sh} ]; then
|
||||
echo "no run.sh in test/${n}"
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "$out"
|
||||
cp -r ${./test + "/${n}"}/* "$out/"
|
||||
chmod +x "$out/run.sh"
|
||||
''
|
||||
else if lib.hasSuffix ".sh" n then
|
||||
pkgs.runCommand "test-${lib.removeSuffix ".sh" n}" {} ''
|
||||
mkdir -p "$out"
|
||||
install -Dm755 ${./test + "/${n}"} "$out/run.sh"
|
||||
''
|
||||
else
|
||||
null
|
||||
) testDir));
|
||||
|
||||
in
|
||||
(lib.mapAttrs' (name: drv: lib.nameValuePair "windows-${name}" (mkTest "windows-${name}" drv)) testDrvs)
|
||||
3
test/package/windows-devshell/launch.sh
Normal file
3
test/package/windows-devshell/launch.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
set -eu
|
||||
|
||||
. "$test/run.sh"
|
||||
64
test/package/windows-devshell/test/standalone-structure.sh
Normal file
64
test/package/windows-devshell/test/standalone-structure.sh
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/bin/dash
|
||||
set -eu
|
||||
|
||||
log info "Checking windows-devshell standalone script structure..."
|
||||
|
||||
# Check file exists
|
||||
if ! [ -f "${windowsDevShellStandalone}" ]; then
|
||||
log error "windows-devshell standalone script not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check it's a PowerShell script (should NOT have hardcoded #Requires -RunAsAdministrator)
|
||||
if head -1 "${windowsDevShellStandalone}" | grep -q "#Requires -RunAsAdministrator"; then
|
||||
log error "Script should not hardcode #Requires -RunAsAdministrator"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check it contains base64 placeholder replacement (should be actual base64 now)
|
||||
if grep -q "@LINUX_DEVSHELL_BASE64@" "${windowsDevShellStandalone}"; then
|
||||
log error "Base64 placeholder was not replaced"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check it contains the base64 decode logic
|
||||
if ! grep -q "FromBase64String" "${windowsDevShellStandalone}"; then
|
||||
log error "Script missing base64 decode logic"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check it contains WSL installation logic
|
||||
if ! grep -q "wsl --status" "${windowsDevShellStandalone}"; then
|
||||
log error "Script missing WSL status check"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -q "wsl --install" "${windowsDevShellStandalone}"; then
|
||||
log error "Script missing WSL install command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check it contains admin check
|
||||
if ! grep -q "Administrator" "${windowsDevShellStandalone}"; then
|
||||
log error "Script missing admin privilege check"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log success "Standalone script has correct structure"
|
||||
|
||||
# Verify the embedded base64 is valid by checking it's non-empty and only contains base64 chars
|
||||
base64_content=$(grep '^\$linuxDevShellBase64 = ' "${windowsDevShellStandalone}" | sed 's/.*= "//;s/"$//')
|
||||
if [ -z "$base64_content" ]; then
|
||||
log error "Embedded base64 content is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check base64 content length is reasonable (should be at least a few hundred chars for the linux script)
|
||||
content_len=${#base64_content}
|
||||
if [ "$content_len" -lt 100 ]; then
|
||||
log error "Embedded base64 content too short ($content_len chars)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log success "Embedded base64 content looks valid ($content_len chars)"
|
||||
log success "Standalone structure test passed"
|
||||
40
test/package/windows-devshell/test/syntax-check.sh
Normal file
40
test/package/windows-devshell/test/syntax-check.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/dash
|
||||
set -eu
|
||||
|
||||
log info "Checking PowerShell script syntax (basic validation)..."
|
||||
|
||||
# Since we can't run PowerShell in Nix, we do basic structural validation
|
||||
|
||||
# Check for balanced braces
|
||||
open_braces=$(grep -o '{' "${windowsDevShellStandalone}" | wc -l)
|
||||
close_braces=$(grep -o '}' "${windowsDevShellStandalone}" | wc -l)
|
||||
if [ "$open_braces" -ne "$close_braces" ]; then
|
||||
log error "Unbalanced braces: $open_braces open, $close_braces close"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for balanced parentheses
|
||||
open_parens=$(grep -o '(' "${windowsDevShellStandalone}" | wc -l)
|
||||
close_parens=$(grep -o ')' "${windowsDevShellStandalone}" | wc -l)
|
||||
if [ "$open_parens" -ne "$close_parens" ]; then
|
||||
log error "Unbalanced parentheses: $open_parens open, $close_parens close"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check no obvious syntax errors (unclosed strings)
|
||||
# Count quotes - should be even
|
||||
quotes=$(grep -o '"' "${windowsDevShellStandalone}" | wc -l)
|
||||
if [ $((quotes % 2)) -ne 0 ]; then
|
||||
log error "Unbalanced quotes: $quotes total (should be even)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check script has reasonable length
|
||||
lines=$(wc -l < "${windowsDevShellStandalone}")
|
||||
if [ "$lines" -lt 50 ]; then
|
||||
log error "Script too short ($lines lines)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log success "PowerShell script passes basic structural validation"
|
||||
log success "Script is $lines lines, braces/parentheses/quotes balanced"
|
||||
Reference in New Issue
Block a user