|
| 1 | +import {setup} from '../../../setup.mjs'; |
| 2 | + |
| 3 | +const appName = 'QAAgentTest'; |
| 4 | + |
| 5 | +setup({ |
| 6 | + neoConfig: { |
| 7 | + allowVdomUpdatesInTests: false, |
| 8 | + unitTestMode : true, |
| 9 | + useDomApiRenderer : false |
| 10 | + }, |
| 11 | + appConfig: { |
| 12 | + name : appName, |
| 13 | + isMounted : () => true, |
| 14 | + vnodeInitialising: false |
| 15 | + } |
| 16 | +}); |
| 17 | + |
| 18 | +import {test, expect} from '@playwright/test'; |
| 19 | +import Neo from '../../../../../src/Neo.mjs'; |
| 20 | +import * as core from '../../../../../src/core/_export.mjs'; |
| 21 | +import Agent from '../../../../../ai/Agent.mjs'; |
| 22 | +import Assembler from '../../../../../ai/context/Assembler.mjs'; |
| 23 | +import path from 'path'; |
| 24 | +import {fileURLToPath} from 'url'; |
| 25 | +import dotenv from 'dotenv'; |
| 26 | + |
| 27 | +const __filename = fileURLToPath(import.meta.url); |
| 28 | +const __dirname = path.dirname(__filename); |
| 29 | +dotenv.config({path: path.resolve(__dirname, '../../../../../.env'), quiet: true}); |
| 30 | + |
| 31 | +test.describe('QA Sub-Agent Swarm Node', () => { |
| 32 | + let primaryAgent; |
| 33 | + let originalAssemble; |
| 34 | + |
| 35 | + test.beforeAll(() => { |
| 36 | + originalAssemble = Assembler.prototype.assemble; |
| 37 | + // Mock the ContextAssembler across the entire Swarm to prevent |
| 38 | + // offline Test nodes from trying to query the live MCP Vector Databases. |
| 39 | + Assembler.prototype.assemble = async function({systemPrompt, userQuery}) { |
| 40 | + return { |
| 41 | + system: systemPrompt, |
| 42 | + messages: [{ role: 'user', content: userQuery }] |
| 43 | + }; |
| 44 | + }; |
| 45 | + }); |
| 46 | + |
| 47 | + test.afterAll(async () => { |
| 48 | + Assembler.prototype.assemble = originalAssemble; |
| 49 | + if (primaryAgent) { |
| 50 | + await primaryAgent.disconnect(); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + test('Primary Agent delegates unit testing task to QA via Gemma4/Ollama', async () => { |
| 55 | + // Skip test in CI environments or if we explicitly don't have a local daemon |
| 56 | + // Since this relies on a local Ollama daemon hosting gemma-4, we just let it run locally |
| 57 | + // to evaluate the Swarm's intelligence. |
| 58 | + test.setTimeout(120000); // Give Gemma4 up to 2 minutes to generate the test code |
| 59 | + |
| 60 | + // The primary orchestrator boots up |
| 61 | + primaryAgent = Neo.create(Agent, { |
| 62 | + servers: [] |
| 63 | + }); |
| 64 | + |
| 65 | + await primaryAgent.initAsync(); |
| 66 | + |
| 67 | + const request = ` |
| 68 | + Analyze the component 'Neo.button.Base'. |
| 69 | + Write a 100% complete Playwright test suite for it. |
| 70 | + Focus exclusively on DOM mounting and testing the 'text' configuration property mutability. |
| 71 | + Return ONLY the code block and nothing else. |
| 72 | + `; |
| 73 | + |
| 74 | + // We DO NOT mock the delegate method here. We want to actually hit the local Gemma-4 node |
| 75 | + // through the Ollama provider to evaluate its ability to follow the System Prompt rules. |
| 76 | + console.log('Sending request to local Gemma4 Swarm node...'); |
| 77 | + const generatedCode = await primaryAgent.delegate('qa', request); |
| 78 | + |
| 79 | + // Basic sanity checks on the raw AI output string to ensure it adhered to the Neo.mjs Testing Primitives |
| 80 | + expect(typeof generatedCode).toBe('string'); |
| 81 | + expect(generatedCode.length).toBeGreaterThan(100); |
| 82 | + |
| 83 | + // Core assertions to ensure Gemma4 learned the rules from its System Prompt |
| 84 | + expect(generatedCode).toContain('import {setup} from'); |
| 85 | + expect(generatedCode).toContain("import Neo from '../../../../src/Neo.mjs'"); |
| 86 | + expect(generatedCode).toContain('DomApiVnodeCreator'); |
| 87 | + expect(generatedCode).toContain('Neo.create('); |
| 88 | + expect(generatedCode).toContain('initVnode()'); |
| 89 | + expect(generatedCode).toContain('.mounted = true'); |
| 90 | + expect(generatedCode).toContain('.set({'); |
| 91 | + |
| 92 | + console.log('\n--- Gemma4 QA Output Start ---'); |
| 93 | + console.log(generatedCode); |
| 94 | + console.log('--- Gemma4 QA Output End ---\n'); |
| 95 | + }); |
| 96 | +}); |
0 commit comments