Skip to content

Commit d2fad9a

Browse files
committed
Report only allowlisted native startup phases for Windows diagnosis
1 parent 0d475df commit d2fad9a

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@ jobs:
3232
run: dotnet format ManagedCode.GrokSharpSDK.slnx --verify-no-changes
3333
- name: Build
3434
run: dotnet build ManagedCode.GrokSharpSDK.slnx -c Release -warnaserror
35+
- name: Qualify caller-owned prompt file on Windows
36+
if: runner.os == 'Windows'
37+
run: dotnet test --solution ManagedCode.GrokSharpSDK.slnx -c Release --no-build --max-parallel-test-modules 1 -v quiet --maximum-parallel-tests 20 --progress on --ansi on --treenode-filter "/*/*/*/ClosedPromptFile_StreamsNativeTerminalResult"
3538
- name: Real CLI integration tests
3639
run: dotnet test --solution ManagedCode.GrokSharpSDK.slnx -c Release --no-build --max-parallel-test-modules 1 -v quiet --maximum-parallel-tests 20 --progress on --ansi on --treenode-filter "/*/*/*/*[RequiresGrokAuth!=true]"
40+
- name: Report allowlisted native startup phases on failure
41+
if: failure()
42+
run: node -e 'const fs=require("node:fs"),path=require("node:path");const dir="artifacts/diagnostics";if(fs.existsSync(dir)){for(const file of fs.readdirSync(dir).filter(f=>/^[0-9a-f]{32}\.phases\.json$/.test(f))){const allowed=new Set(["config_load","managed_policy","bootstrap","model_catalog","worker_spawn","leader_connect","acp_initialize","eager_auth","app_init","session_create"]);const phases=JSON.parse(fs.readFileSync(path.join(dir,file),"utf8"));console.log("Native startup phases="+phases.filter(p=>allowed.has(p)).join(","));}}'

‎GrokSharpSDK.Tests/NativeFixture.cs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,53 @@ private static string FindRepository()
232232
return directory?.FullName ?? throw new DirectoryNotFoundException("Repository root was not found.");
233233
}
234234

235+
236+
private void WriteStartupPhaseSummary()
237+
{
238+
// Export only labels from upstream's closed StartupPhase enum. Never export raw native records.
239+
string[] known = ["config_load", "managed_policy", "bootstrap", "model_catalog", "worker_spawn",
240+
"leader_connect", "acp_initialize", "eager_auth", "app_init", "session_create"];
241+
var phases = new List<string>();
242+
var log = Path.Combine(Root, "grok", "logs", "unified.jsonl");
243+
if (File.Exists(log))
244+
{
245+
using var stream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
246+
using var reader = new StreamReader(stream);
247+
while (reader.ReadLine() is { } line)
248+
{
249+
JsonDocument entry;
250+
try
251+
{
252+
entry = JsonDocument.Parse(line);
253+
}
254+
catch (JsonException)
255+
{
256+
// A process terminated during a write may leave a partial final record.
257+
continue;
258+
}
259+
using (entry)
260+
{
261+
var root = entry.RootElement;
262+
if (root.TryGetProperty("msg", out var message) &&
263+
message.GetString() is "startup phase" or "startup phase running long" &&
264+
root.TryGetProperty("ctx", out var context) &&
265+
context.TryGetProperty("phase", out var value) &&
266+
value.GetString() is { } phase && known.Contains(phase, StringComparer.Ordinal))
267+
{
268+
phases.Add(phase);
269+
}
270+
}
271+
}
272+
}
273+
var diagnostics = Directory.CreateDirectory(Path.Combine(FindRepository(), "artifacts", "diagnostics")).FullName;
274+
File.WriteAllText(Path.Combine(diagnostics, Path.GetFileName(Root) + ".phases.json"), JsonSerializer.Serialize(phases));
275+
}
276+
235277
public async ValueTask DisposeAsync()
236278
{
237279
await _server.StopAsync();
238280
await _server.DisposeAsync();
281+
WriteStartupPhaseSummary();
239282
Directory.Delete(Root, recursive: true);
240283
}
241284
}

‎docs/Testing.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ dotnet test --solution ManagedCode.GrokSharpSDK.slnx -c Release --max-parallel-t
2424
It cannot validate completed browser approval without a user-authorized account. Default CI excludes that test. No hosted models are called.
2525

2626
CI runs the deterministic real-CLI suite on Linux, Windows and macOS. NuGet publication runs only after the exact main-branch commit passes CI. Publication failures fail the release job. Credentials are supplied by repository/organization secrets and are never generated by the SDK.
27+
28+
On failure CI reports only labels from upstream's closed startup-phase enum. The fixture exports those allowlisted labels before cleanup; raw native log records, prompts, paths, credentials and file content are never uploaded or printed by this diagnostic.

0 commit comments

Comments
 (0)