Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

5.2 KB
Raw Blame
import test from 'node:test';
import assert from 'node:assert/strict';
import {createToolLoopGuard, userMessageRequestsWorkspacePreview} from '../plugin/tool-loop-guard.mjs';

for (const prompt of [
  'Crie despesas.csv e resumo.md, leia os dois e entregue links para baixar. Não crie site e não publique preview.',
  'Create expenses.csv and summary.md and provide downloads. Do not publish a preview.',
  'Em Playground/ods-qa-delivery-retest-20260930-1525, crie despesas.csv com cabeçalho categoria,valor e duas linhas Hospedagem,120 e Domínio,40. Crie também resumo.md em português informando total de R$ 160,00. Leia os dois arquivos de volta e entregue links para baixar ambos com esses nomes. Não crie site nem publique preview. Não apague nada existente.',
  'Crie os arquivos para download. Não construa um site nem mostre uma pré-visualização.',
  'Crie um CSV. Não edite os arquivos existentes ou publique um preview.',
  'Create downloadable files. Do not create a website nor publish a preview.',
  'Create downloadable files. Do not create a website and publish a preview.',
  'Create downloadable files. Do not try to create a website and publish a preview.',
  'Create downloadable files. Do not use libraries or publish a preview.',
]) {
  test(`a declined preview error does not invent a website delivery obligation: ${prompt}`, () => {
    const guard=createToolLoopGuard();
    const context={agentId:'pixel',runId:'file-delivery',sessionId:'file-delivery',toolCallId:'preview'};
    guard.observeRun(context,'pixel',{prompt});
    assert.equal(userMessageRequestsWorkspacePreview([],prompt),false);
    assert.equal(guard.verificationForRun(context.runId).status,'none');
    const event={toolName:'pixel_ods_workspace_preview',params:{relativeDirectory:'reports'}};
    const refusal=guard.beforeToolCall(event,context);
    assert.equal(refusal.block,true);
    guard.afterToolCall({...event,result:{isError:true,content:[{type:'text',text:refusal.blockReason}]}},context);
    const verification=guard.verificationForRun(context.runId);
    assert.equal(verification.status,'none');
    assert.equal(verification.preview,undefined);
    assert.doesNotMatch(verification.text ?? '',/website|preview is ready/);
    // Unexpected success after denial must never become a valid publication.
    guard.afterToolCall({...event,result:{isError:false,details:{status:'published'}}},context);
    assert.equal(guard.verificationForRun(context.runId).status,'failed');
  });
}

test('independent positive publication and real websites keep their verification obligation',()=>{
  for (const prompt of ['Crie um site e publique preview.',
    'Crie um site sem dependências e publique uma prévia.',
    'Não use bibliotecas externas e publique o site.',
    'Crie uma página sem imagens e publique o preview.',
    'Create a website without dependencies and publish a preview.',
    'Do not use external libraries and publish the website.',
    'Create the files without images and publish the website.',
    'Não altere os arquivos. Publique o site existente.',
    'Do not delete the files, but publish the existing website.']) {
    const guard=createToolLoopGuard();
    const context={agentId:'pixel',runId:prompt,sessionId:'positive'};
    guard.observeRun(context,'pixel',{prompt});
    assert.equal(userMessageRequestsWorkspacePreview([],prompt),true,prompt);
    assert.equal(guard.verificationForRun(context.runId).status,'failed',prompt);
  }
});

test('a failed requested preview still reports incomplete website delivery',()=>{
  const guard=createToolLoopGuard();
  const context={agentId:'pixel',runId:'site',sessionId:'site'};
  guard.observeRun(context,'pixel',{prompt:'Build and publish a website preview.'});
  guard.afterToolCall({toolName:'pixel_ods_workspace_preview',params:{relativeDirectory:'site'},result:{isError:true}},context);
  assert.equal(guard.verificationForRun(context.runId).status,'failed');
  assert.match(guard.verificationForRun(context.runId).text,/website/);
});


test('file publication cannot acquire a website target from a later sentence or constraint',()=>{
  const prompt='Os nomes na resposta não são links nem botões de download. Publique os arquivos pela ferramenta de entrega de arquivos do Portal. Antes, corrija o ZIP: preserve src/inventario.py, tests/test_inventario.py e tools/gerar_lock.py nos caminhos originais, junto de main.py e dos manifests. Achatar a estrutura quebra os imports e a descoberta de testes. Verifique a listagem final e entregue PDF e ZIP com downloads clicáveis, sem criar site nem novo projeto.';
  const guard=createToolLoopGuard(),context={agentId:'pixel',runId:'files-only',sessionId:'files-only'};
  guard.observeRun(context,'pixel',{prompt});
  assert.equal(userMessageRequestsWorkspacePreview([],prompt),false);
  assert.equal(guard.verificationForRun(context.runId).status,'none');
  for(const value of ['Publique os arquivos sem criar site nem novo projeto.','Publique os arquivos. Não crie site.'])assert.equal(userMessageRequestsWorkspacePreview([],value),false,value);
  for(const value of ['Publique o site sem alterar os arquivos.','Publique os arquivos. Depois publique o site.'])assert.equal(userMessageRequestsWorkspacePreview([],value),true,value);
});