Skip to content

Commit 9d4fb55

Browse files
committed
Validate config dir is used in tests
1 parent defa578 commit 9d4fb55

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

dotnet/test/SessionTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ public async Task Should_Create_Session_With_Custom_Config_Dir()
331331

332332
Assert.Matches(@"^[a-f0-9-]+$", session.SessionId);
333333

334+
// Verify config.json was written to the custom config dir
335+
var configPath = Path.Combine(customConfigDir, "github-copilot", "config.json");
336+
Assert.True(File.Exists(configPath), $"Expected config.json at {configPath}");
337+
var configContent = System.Text.Json.JsonDocument.Parse(await File.ReadAllTextAsync(configPath));
338+
Assert.Equal(session.SessionId, configContent.RootElement.GetProperty("sessionId").GetString());
339+
334340
// Session should work normally with custom config dir
335341
await session.SendAsync(new MessageOptions { Prompt = "What is 1+1?" });
336342
var assistantMessage = await TestHelper.GetFinalAssistantMessageAsync(session);

go/e2e/session_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package e2e
22

33
import (
4+
"encoding/json"
5+
"os"
46
"regexp"
57
"strings"
68
"testing"
@@ -704,6 +706,20 @@ func TestSession(t *testing.T) {
704706
t.Errorf("Expected session ID to match UUID pattern, got %q", session.SessionID)
705707
}
706708

709+
// Verify config.json was written to the custom config dir
710+
configPath := customConfigDir + "/github-copilot/config.json"
711+
configData, err := os.ReadFile(configPath)
712+
if err != nil {
713+
t.Fatalf("Failed to read config.json at %s: %v", configPath, err)
714+
}
715+
var configContent map[string]interface{}
716+
if err := json.Unmarshal(configData, &configContent); err != nil {
717+
t.Fatalf("Failed to parse config.json: %v", err)
718+
}
719+
if configContent["sessionId"] != session.SessionID {
720+
t.Errorf("Expected config.json sessionId to be %q, got %v", session.SessionID, configContent["sessionId"])
721+
}
722+
707723
// Session should work normally with custom config dir
708724
_, err = session.Send(copilot.MessageOptions{Prompt: "What is 1+1?"})
709725
if err != nil {

nodejs/test/e2e/session.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from "node:fs";
12
import { describe, expect, it, onTestFinished } from "vitest";
23
import { ParsedHttpExchange } from "../../../test/harness/replayingCapiProxy.js";
34
import { CopilotClient } from "../../src/index.js";
@@ -343,6 +344,12 @@ describe("Sessions", async () => {
343344

344345
expect(session.sessionId).toMatch(/^[a-f0-9-]+$/);
345346

347+
// Verify config.json was written to the custom config dir
348+
const configPath = `${customConfigDir}/github-copilot/config.json`;
349+
expect(fs.existsSync(configPath)).toBe(true);
350+
const configContent = JSON.parse(fs.readFileSync(configPath, "utf-8"));
351+
expect(configContent).toHaveProperty("sessionId", session.sessionId);
352+
346353
// Session should work normally with custom config dir
347354
await session.send({ prompt: "What is 1+1?" });
348355
const assistantMessage = await getFinalAssistantMessage(session);

python/e2e/test_session.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,21 @@ def on_event(event):
361361
assert "300" in assistant_message.data.content
362362

363363
async def test_should_create_session_with_custom_config_dir(self, ctx: E2ETestContext):
364+
import json
364365
import os
365366

366367
custom_config_dir = os.path.join(ctx.home_dir, "custom-config")
367368
session = await ctx.client.create_session({"config_dir": custom_config_dir})
368369

369370
assert session.session_id
370371

372+
# Verify config.json was written to the custom config dir
373+
config_path = os.path.join(custom_config_dir, "github-copilot", "config.json")
374+
assert os.path.exists(config_path), f"Expected config.json at {config_path}"
375+
with open(config_path) as f:
376+
config_content = json.load(f)
377+
assert config_content.get("sessionId") == session.session_id
378+
371379
# Session should work normally with custom config dir
372380
await session.send({"prompt": "What is 1+1?"})
373381
assistant_message = await get_final_assistant_message(session)

0 commit comments

Comments
 (0)