import assert from 'node:assert/strict';
import test from 'node:test';
import { ExecutorCommandSchema } from '@platform-modules/chatgpt-orchestrator-protocol';
import { createSteeringCommand, deliveryCommandId } from '../src/steering.js';

test('steering idempotency key deterministically owns one command id', () => {
  const key = 'checkpoint:run-1:worker-1:sequence-4';
  assert.equal(deliveryCommandId(key), deliveryCommandId(key));
  assert.notEqual(deliveryCommandId(key), deliveryCommandId(`${key}:other`));
});

test('steering command is protocol-valid and stable across retry construction', () => {
  const workerId = `wrk_${crypto.randomUUID()}` as const;
  const deadline = new Date(Date.now() + 60_000).toISOString();
  const input = { workerId, prompt: 'Report status to root, then continue.', reason: 'checkpoint' as const, idempotencyKey: 'checkpoint:test:1', deadline };
  const first = createSteeringCommand(input);
  const retry = createSteeringCommand(input);
  assert.deepEqual(retry, first);
  assert.equal(ExecutorCommandSchema.parse(first).type, 'conversation.steer');
});
