graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
test (#477): prove the home-less credential resolution end to end
Rach Pradhand2584a5fe42f
diff --git a/src/credential_store.zig b/src/credential_store.zigindex ed04ff7e..2a6b2c65 100644--- a/src/credential_store.zig+++ b/src/credential_store.zig@@ -138,21 +138,9 @@ test "replaceFile: renames a whole new file into place, never truncating the tartry std.testing.expectEqual(@as(usize, 1), try entryCount(io, tmp.dir));}-test "oauthPath (#477): a home-less caller resolves the startup-pinned home, never the fs root" {- var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);- defer arena_state.deinit();- const a = arena_state.allocator();- const saved = g_home;- defer g_home = saved;- g_home = "/pinned/home";- // The throwaway-agent case (home=""): the pinned home, not "/.kimi/...".- try std.testing.expectEqualStrings("/pinned/home/.kimi/credentials/graff-oauth.json", oauthPath(a, "", ".kimi"));- // A caller that HAS a home is untouched — the pin is a fallback, not an override.- try std.testing.expectEqualStrings("/caller/home/.xai/credentials/graff-oauth.json", oauthPath(a, "/caller/home", ".xai"));- // Before startup pins anything the old (broken but unchanged) shape survives.- g_home = "";- try std.testing.expectEqualStrings("/.kimi/credentials/graff-oauth.json", oauthPath(a, "", ".kimi"));-}+// The #477 g_home fallback test lives in startup_tests.zig (with the other+// credential-scope regressions): exactly ONE test in the suite may mutate+// g_home, because the parallel test runner makes two mutators a coin flip.test "replaceFile: .default_file keeps umask in charge and never widens an existing mode" {if (builtin.os.tag == .windows) return;diff --git a/src/startup_tests.zig b/src/startup_tests.zigindex 2f5b79e8..13a81136 100644--- a/src/startup_tests.zig+++ b/src/startup_tests.zig@@ -77,3 +77,39 @@ test "resolveKeys does not load Kimi/xAI OAuth credentials for an explicit unrel} else unreachable;try std.testing.expect(startup.startupStoredKeyScope("deepseek", true, "kimi").includes(kimi_idx, "kimi"));}++test "kimi oauth (#477): a home-less side agent resolves the startup-pinned home — real writer, real loader" {+ // The reported bug, end to end without the network: the pre-compaction+ // note agent (home="") could neither proactively refresh nor recover a+ // 401, because its credential path resolved to "/.kimi/...". Pin the+ // process home as startup does, then prove the home-less call shape+ // finds what the real writer wrote. The ONLY g_home mutation in the+ // suite — the parallel runner makes two mutators a coin flip.+ if (builtin.os.tag == .windows) return error.SkipZigTest;+ const io = std.testing.io;+ const gpa = std.testing.allocator;+ var arena_state = std.heap.ArenaAllocator.init(gpa);+ defer arena_state.deinit();+ const arena = arena_state.allocator();+ const credential_store = @import("credential_store.zig");+ const oauth = @import("oauth.zig");++ var tmp = std.testing.tmpDir(.{});+ defer tmp.cleanup();+ var real_buf: [std.fs.max_path_bytes]u8 = undefined;+ const real_len = try tmp.dir.realPath(io, &real_buf);+ const home = try arena.dupe(u8, real_buf[0..real_len]);++ const saved = credential_store.g_home;+ defer credential_store.g_home = saved;+ credential_store.initHome(home);++ // Path shapes: the pin fills in for a home-less caller, never overrides one.+ try std.testing.expectEqualStrings(try std.fmt.allocPrint(arena, "{s}/.kimi/credentials/graff-oauth.json", .{home}), credential_store.oauthPath(arena, "", ".kimi"));+ try std.testing.expectEqualStrings("/caller/.xai/credentials/graff-oauth.json", credential_store.oauthPath(arena, "/caller", ".xai"));++ // The fix itself: write through the real writer, load with home="" — the+ // note agent's exact call shape. Far-future expiry: no refresh, no network.+ try credential_store.writeOAuth(io, arena, home, ".kimi", "kimi-access-477", "kimi-refresh", 4102444800);+ try std.testing.expectEqualStrings("kimi-access-477", oauth.loadKimiOAuth(io, gpa, arena, "", false, null).?);+}