Normalize native launcher source and test file endings
Server CI and Windows package / verify (push) Successful in 1m44s
Server CI and Windows package / windows-package (push) Successful in 9m44s

This commit is contained in:
yilsem committed 2026-10-12 19:28:37 +03:00
1 parent b66d9164ad
commit b4e8664115
4 files changed
+51 -53

No files matched your search

+1 -1
View File
@@ -1,2 +1,2 @@
# Generated by beforePack from NativeWatchBootstrap.cs; never commit opaque output. # Generated by beforePack from NativeWatchBootstrap.cs; never commit opaque output.
/native-watch.exe /native-watch.exe
@@ -1,14 +1,14 @@
// Thin Windows CLI_PATH executable. Runtime and original are owner-provisioned, // Thin Windows CLI_PATH executable. Runtime and original are owner-provisioned,
// absolute, SHA-pinned; never consult PATH or CODEX_CLI_PATH. // absolute, SHA-pinned; never consult PATH or CODEX_CLI_PATH.
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Diagnostics; using System.Diagnostics;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
class NativeWatchBootstrap { class NativeWatchBootstrap {
// Assign this bootstrap BEFORE creating Python. Descendants inherit job // Assign this bootstrap BEFORE creating Python. Descendants inherit job
// membership atomically; the non-inheritable handle belongs only to us. // membership atomically; the non-inheritable handle belongs only to us.
@@ -44,46 +44,46 @@ class NativeWatchBootstrap {
// Do not close here or in finally: the bootstrap is itself a member. // Do not close here or in finally: the bootstrap is itself a member.
// The OS closes this handle at exit, preserving our native exit code. // The OS closes this handle at exit, preserving our native exit code.
} }
static string Quote(string s) { static string Quote(string s) {
var b=new StringBuilder("\""); int slashes=0; var b=new StringBuilder("\""); int slashes=0;
foreach(char c in s) { foreach(char c in s) {
if(c=='\\') {slashes++; continue;} if(c=='\\') {slashes++; continue;}
if(c=='"') { b.Append('\\',slashes*2+1); b.Append(c); } if(c=='"') { b.Append('\\',slashes*2+1); b.Append(c); }
else {b.Append('\\',slashes); b.Append(c);} else {b.Append('\\',slashes); b.Append(c);}
slashes=0; slashes=0;
} }
b.Append('\\',slashes*2); b.Append('"'); return b.ToString(); b.Append('\\',slashes*2); b.Append('"'); return b.ToString();
} }
static string Pin(Dictionary<string,object> c,string field) { static string Pin(Dictionary<string,object> c,string field) {
string p=(string)c[field], expected=(string)c[field+"_sha256"]; string p=(string)c[field], expected=(string)c[field+"_sha256"];
if(!Path.IsPathRooted(p) || String.Equals(Path.GetFullPath(p),Process.GetCurrentProcess().MainModule.FileName,StringComparison.OrdinalIgnoreCase)) throw new Exception(); if(!Path.IsPathRooted(p) || String.Equals(Path.GetFullPath(p),Process.GetCurrentProcess().MainModule.FileName,StringComparison.OrdinalIgnoreCase)) throw new Exception();
using(var f=File.OpenRead(p)) using(var sha=SHA256.Create()) { using(var f=File.OpenRead(p)) using(var sha=SHA256.Create()) {
string actual=BitConverter.ToString(sha.ComputeHash(f)).Replace("-","").ToLowerInvariant(); string actual=BitConverter.ToString(sha.ComputeHash(f)).Replace("-","").ToLowerInvariant();
if(actual!=expected.ToLowerInvariant()) throw new Exception(); if(actual!=expected.ToLowerInvariant()) throw new Exception();
} }
return p; return p;
} }
static void Pump(Stream source, Stream target) { static void Pump(Stream source, Stream target) {
byte[] buffer=new byte[8192]; int count; byte[] buffer=new byte[8192]; int count;
while((count=source.Read(buffer,0,buffer.Length))>0) { target.Write(buffer,0,count); target.Flush(); } while((count=source.Read(buffer,0,buffer.Length))>0) { target.Write(buffer,0,count); target.Flush(); }
} }
static int Main(string[] args) { static int Main(string[] args) {
try { try {
string manifest=Path.ChangeExtension(Process.GetCurrentProcess().MainModule.FileName,".json"); string manifest=Path.ChangeExtension(Process.GetCurrentProcess().MainModule.FileName,".json");
var c=new JavaScriptSerializer().Deserialize<Dictionary<string,object>>(File.ReadAllText(manifest)); var c=new JavaScriptSerializer().Deserialize<Dictionary<string,object>>(File.ReadAllText(manifest));
string original=Pin(c,"original"); string original=Pin(c,"original");
string python=Pin(c,"python"); string python=Pin(c,"python");
string script=Pin(c,"script"); string script=Pin(c,"script");
OwnProcessTree(); OwnProcessTree();
var argv=new List<string>{"-u",script,manifest}; argv.AddRange(args); var argv=new List<string>{"-u",script,manifest}; argv.AddRange(args);
var quoted=new List<string>(); foreach(var a in argv) quoted.Add(Quote(a)); var quoted=new List<string>(); foreach(var a in argv) quoted.Add(Quote(a));
var p=Process.Start(new ProcessStartInfo(python,String.Join(" ",quoted.ToArray())) { UseShellExecute=false, CreateNoWindow=true, RedirectStandardInput=true, RedirectStandardOutput=true, RedirectStandardError=true }); var p=Process.Start(new ProcessStartInfo(python,String.Join(" ",quoted.ToArray())) { UseShellExecute=false, CreateNoWindow=true, RedirectStandardInput=true, RedirectStandardOutput=true, RedirectStandardError=true });
var input=new Thread(()=> { try { Pump(Console.OpenStandardInput(),p.StandardInput.BaseStream); p.StandardInput.Close(); } catch(IOException) {} }); var input=new Thread(()=> { try { Pump(Console.OpenStandardInput(),p.StandardInput.BaseStream); p.StandardInput.Close(); } catch(IOException) {} });
input.IsBackground=true; input.Start(); input.IsBackground=true; input.Start();
var output=new Thread(()=>Pump(p.StandardOutput.BaseStream,Console.OpenStandardOutput())); var output=new Thread(()=>Pump(p.StandardOutput.BaseStream,Console.OpenStandardOutput()));
var error=new Thread(()=>Pump(p.StandardError.BaseStream,Console.OpenStandardError())); var error=new Thread(()=>Pump(p.StandardError.BaseStream,Console.OpenStandardError()));
output.Start(); error.Start(); output.Start(); error.Start();
p.WaitForExit(); output.Join(); error.Join(); return p.ExitCode; p.WaitForExit(); output.Join(); error.Join(); return p.ExitCode;
} catch { Console.Error.WriteLine("Owned native launcher integrity/configuration failure."); return 78; } } catch { Console.Error.WriteLine("Owned native launcher integrity/configuration failure."); return 78; }
} }
} }
@@ -355,4 +355,3 @@ def test_verified_original_launcher_fallback_actual_process(tmp_path):
raise AssertionError('not an app-server invocation') raise AssertionError('not an app-server invocation')
assert muxmod.launch_original(executable,digest,['-c',code,str(marker),'app-server'],attach=forbidden) == 21 assert muxmod.launch_original(executable,digest,['-c',code,str(marker),'app-server'],attach=forbidden) == 21
assert marker.read_text() == 'ok' assert marker.read_text() == 'ok'
@@ -113,4 +113,3 @@ def test_executable_flushes_interactive_stdin_before_eof(tmp_path):
assert q.get(timeout=5).strip()==b'live-before-eof' assert q.get(timeout=5).strip()==b'live-before-eof'
finally: finally:
p.stdin.close();p.wait(timeout=5) p.stdin.close();p.wait(timeout=5)