refactor: renaming api

This commit is contained in:
2026-04-06 09:48:20 +08:00
parent 8c2c6dc94c
commit 2d5200bdb7
7 changed files with 42 additions and 42 deletions
+23 -23
View File
@@ -59,7 +59,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
const promptEvent = await promptPromise;
expect(promptEvent.schema.name).toBe('play');
@@ -68,7 +68,7 @@ describe('GameHost', () => {
const error = host.onInput('play X 1 1');
expect(error).toBeNull();
// Cancel to end the game since setup runs until game over
// Cancel to end the game since start runs until game over
const nextPromptPromise = waitForPromptEvent(host);
const nextPrompt = await nextPromptPromise;
nextPrompt.cancel('test cleanup');
@@ -81,7 +81,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
const promptEvent = await promptPromise;
@@ -106,7 +106,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
const promptEvent = await promptPromise;
const schema = host.activePromptSchema.value;
@@ -125,13 +125,13 @@ describe('GameHost', () => {
});
});
describe('setup', () => {
it('should reset state and run setup command', async () => {
describe('start', () => {
it('should reset state and run start command', async () => {
const { host } = createTestHost();
// First setup - make one move
let promptPromise = waitForPromptEvent(host);
let runPromise = host.context._commands.run('setup');
let runPromise = host.context._commands.run('start');
let promptEvent = await promptPromise;
// Make a move
@@ -146,11 +146,11 @@ describe('GameHost', () => {
expect(result.success).toBe(false); // Cancelled
expect(Object.keys(host.context._state.value.parts).length).toBe(1);
// Setup listener before calling setup
// Setup listener before calling start
const newPromptPromise = waitForPromptEvent(host);
// Reset - should reset state and start new game
host.setup('setup');
host.start('start');
// State should be back to initial
expect(host.context._state.value.currentPlayer).toBe('X');
@@ -164,16 +164,16 @@ describe('GameHost', () => {
newPrompt.cancel('test end');
});
it('should cancel active prompt during setup', async () => {
it('should cancel active prompt during start', async () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
await promptPromise;
// Setup should cancel the active prompt and reset state
host.setup('setup');
host.start('start');
// The original runPromise should be rejected due to cancellation
try {
@@ -192,7 +192,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
host.dispose();
expect(() => host.setup('setup')).toThrow('GameHost is disposed');
expect(() => host.start('start')).toThrow('GameHost is disposed');
});
});
@@ -208,7 +208,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
await promptPromise;
@@ -233,11 +233,11 @@ describe('GameHost', () => {
});
describe('events', () => {
it('should emit setup event', async () => {
it('should emit start event', async () => {
const { host } = createTestHost();
let setupCount = 0;
host.on('setup', () => {
host.on('start', () => {
setupCount++;
});
@@ -245,7 +245,7 @@ describe('GameHost', () => {
const promptPromise = waitForPromptEvent(host);
// Initial setup via reset
host.setup('setup');
host.start('start');
expect(setupCount).toBe(1);
// State should be running
@@ -272,7 +272,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
let setupCount = 0;
const unsubscribe = host.on('setup', () => {
const unsubscribe = host.on('start', () => {
setupCount++;
});
@@ -294,7 +294,7 @@ describe('GameHost', () => {
// Make a move
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
const promptEvent = await promptPromise;
promptEvent.tryCommit({ name: 'play', params: ['X', 1, 1], options: {}, flags: {} });
@@ -320,7 +320,7 @@ describe('GameHost', () => {
// Start a command that triggers prompt
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
await promptPromise;
@@ -369,7 +369,7 @@ describe('GameHost', () => {
});
// Start setup command (runs game loop until completion)
const setupPromise = host.context._commands.run('setup');
const setupPromise = host.context._commands.run('start');
for (let i = 0; i < moves.length; i++) {
// Wait until the next prompt event arrives
@@ -415,7 +415,7 @@ describe('GameHost', () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.context._commands.run('setup');
const runPromise = host.context._commands.run('start');
const promptEvent = await promptPromise;
expect(promptEvent.currentPlayer).toBe('X');
@@ -433,7 +433,7 @@ describe('GameHost', () => {
// First prompt - X's turn
let promptPromise = waitForPromptEvent(host);
let runPromise = host.context._commands.run('setup');
let runPromise = host.context._commands.run('start');
let promptEvent = await promptPromise;
expect(promptEvent.currentPlayer).toBe('X');
expect(host.activePromptPlayer.value).toBe('X');
+2 -2
View File
@@ -176,7 +176,7 @@ describe('TicTacToe - game flow', () => {
it('should have setup and turn commands registered', () => {
const { registry: reg } = createTestContext();
expect(reg.has('setup')).toBe(true);
expect(reg.has('start')).toBe(true);
expect(reg.has('turn')).toBe(true);
});
@@ -184,7 +184,7 @@ describe('TicTacToe - game flow', () => {
const { ctx } = createTestContext();
const promptPromise = waitForPrompt(ctx);
const runPromise = ctx.run('setup');
const runPromise = ctx.run('start');
const promptEvent = await promptPromise;
expect(promptEvent).not.toBeNull();