Skip to content

Commit 9d9d384

Browse files
committed
fix: E2E テストの config を v2 フォーマットで統一し認証フレーキーテストを修正
writeConfig() に v1→v2 自動ラップを追加し、CLI プロセスでの auto-migration(ファイル再書き込み)を不要にした。 これにより別プロセス間のファイル I/O タイミング問題を解消。
1 parent 10a4e7c commit 9d9d384

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

tests/e2e/step_definitions/auth.steps.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ Given("I am logged in", async function (this: GdbWorld) {
77
});
88

99
Given("I am logged in with token {string}", function (this: GdbWorld, token: string) {
10-
const config = this.readConfig();
11-
config.token = token;
12-
config.url = config.url ?? this.serverUrl;
13-
this.writeConfig(config);
10+
this.writeConfig({ url: this.serverUrl, token });
1411
});
1512

1613
Given("I am not logged in", function (this: GdbWorld) {

tests/e2e/step_definitions/token.steps.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Given("I am logged in with an invalidated token", async function (this: GdbWorld
55
await performLogin(this);
66

77
// Invalidate the token but keep the refreshToken intact
8-
const config = this.readConfig();
9-
config.token = "invalidated";
10-
this.writeConfig(config);
8+
const full = this.readFullConfig();
9+
const profiles = full.profiles as Record<string, Record<string, unknown>>;
10+
const active = (full.currentProfile as string) ?? "default";
11+
profiles[active].token = "invalidated";
12+
this.writeConfig(full);
1113
});

tests/e2e/support/world.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ export class GdbWorld extends World {
6868
}
6969
}
7070

71-
/** Write a config file in the temp config dir */
71+
/** Write a config file in the temp config dir (auto-wraps v1 flat configs into v2 format) */
7272
writeConfig(config: Record<string, unknown>): void {
7373
mkdirSync(this.configDir, { recursive: true });
74-
writeFileSync(join(this.configDir, "config.json"), JSON.stringify(config, null, 2) + "\n");
74+
// Ensure v2 format so the CLI doesn't need to auto-migrate (avoids extra file I/O)
75+
const toWrite = config.version === 2 ? config : {
76+
version: 2,
77+
currentProfile: "default",
78+
profiles: { default: config },
79+
};
80+
writeFileSync(join(this.configDir, "config.json"), JSON.stringify(toWrite, null, 2) + "\n");
7581
}
7682

7783
/** Read the current config file (raw JSON) */
@@ -133,9 +139,13 @@ export async function performLogin(world: GdbWorld): Promise<Record<string, unkn
133139
continue;
134140
}
135141

136-
const config: Record<string, unknown> = { url: world.serverUrl, token };
137-
if (data.refreshToken) config.refreshToken = data.refreshToken;
138-
world.writeConfig(config);
142+
const profile: Record<string, unknown> = { url: world.serverUrl, token };
143+
if (data.refreshToken) profile.refreshToken = data.refreshToken;
144+
world.writeConfig({
145+
version: 2,
146+
currentProfile: "default",
147+
profiles: { default: profile },
148+
});
139149
return world.readProfileConfig();
140150
} catch (err) {
141151
lastError = err instanceof Error ? err : new Error(String(err));

0 commit comments

Comments
 (0)