AI 怎么从例子里学会? · 算法游乐场
+ AI 怎么从例子里学会? · 算法游乐场
diff --git a/src/learning/learning-route-trials.mjs b/src/learning/learning-route-trials.mjs
index c6bbd63..a8b2eb6 100644
--- a/src/learning/learning-route-trials.mjs
+++ b/src/learning/learning-route-trials.mjs
@@ -1,6 +1,6 @@
import {createLearningRoute,actLearningRoute} from './learning-route.mjs';
import {gradientEvidence} from '../experiments/neural/neural-gradient.mjs';
-import {replayLearningReceipt} from '../integrations/learning-tool.mjs';
+import {replayLearningReceipt} from '../integrations/learning-tool.mjs?v=agent-frames-v1';
const wire=n=>Number(n.toPrecision(12));
diff --git a/src/learning/learning-route-ui.mjs b/src/learning/learning-route-ui.mjs
index 0dad32b..9c22c98 100644
--- a/src/learning/learning-route-ui.mjs
+++ b/src/learning/learning-route-ui.mjs
@@ -1,9 +1,9 @@
-import {createLearningRoute,actLearningRoute,learningRouteEvidence} from './learning-route.mjs?v=route-return-v1';
+import {createLearningRoute,actLearningRoute,learningRouteEvidence} from './learning-route.mjs';
import {paintGuide} from '../experiments/neural/neural-guide-view.mjs';
import {paintGeneralization} from '../experiments/neural/neural-generalization-view.mjs';
-import {runLearningRoute} from '../integrations/learning-tool.mjs?v=learning-tool-v1';
+import {runLearningRoute} from '../integrations/learning-tool.mjs?v=agent-frames-v1';
import {readGenaiHandoffContext,createGenaiReturnUrl} from '../integrations/genai-handoff.mjs?v=handoff-trust-v1';
-import {inspectLearningRouteTrials} from './learning-route-trials.mjs?v=handoff-trust-v1';
+import {inspectLearningRouteTrials} from './learning-route-trials.mjs?v=route-load-v1';
import {saveRouteReturn,consumeRouteReturn} from './learning-route-return.mjs?v=route-return-v1';
const shape=n=>n?'方':'圆';
function markExample(canvas,p,dark){
diff --git a/tests/delivery/learning-route-delivery.test.mjs b/tests/delivery/learning-route-delivery.test.mjs
index 79c731f..709abb6 100644
--- a/tests/delivery/learning-route-delivery.test.mjs
+++ b/tests/delivery/learning-route-delivery.test.mjs
@@ -14,9 +14,15 @@ test('homepage learning route serves real assets, valid legacy exits and exact b
const releaseUrls=[home,page].flatMap(doc=>[...doc.matchAll(/(?:href|src)="(\.\/(?:home\.css|learning-route(?:-ui)?\.(?:css|mjs))[^" ]*)"/g)].map(m=>new URL(m[1],base)));
assert.equal(releaseUrls.length,4,'both pages must ship the route styling and focused entry');
const version=releaseUrls.find(u=>u.pathname.endsWith('learning-route-ui.mjs')).searchParams.get('v');assert.ok(version,'changed route must not reuse an unversioned controller cache');
+ for(const url of releaseUrls)assert.ok(url.searchParams.get('v'),'page entry scripts and styles remain versioned');
const ui=await(await fetch(releaseUrls.find(u=>u.pathname.endsWith('learning-route-ui.mjs')))).text();
const model=ui.match(/from\s+['"]([^'"]*learning-route\.mjs[^'"]*)['"]/)?.[1];assert.ok(model);releaseUrls.push(new URL(model,base));
- for(const url of releaseUrls){assert.ok(url.searchParams.get('v'),'every delivered asset remains versioned');if(url.pathname!=='/home.css')assert.equal(url.searchParams.get('v'),version,'the changed route graph must use one release key');const asset=await fetch(url);assert.equal(asset.status,200);assert.deepEqual(Buffer.from(await asset.arrayBuffer()),await readFile(new URL(url.pathname.slice(1),root)));}
+ const trials=ui.match(/from\s+['"]([^'"]*learning-route-trials\.mjs[^'"]*)['"]/)?.[1];assert.ok(trials);const trialsUrl=new URL(trials,base);
+ assert.ok(trialsUrl.searchParams.get('v'),'changed trial consumer remains versioned');releaseUrls.push(trialsUrl);
+ // Assets need not share one cache key: unchanged styles keep their URL, and
+ // the engine shares its canonical URL with replay/trial consumers. Actual
+ // engine instantiation counts are covered by learning-route-loading.test.
+ for(const url of releaseUrls){const asset=await fetch(url);assert.equal(asset.status,200);assert.deepEqual(Buffer.from(await asset.arrayBuffer()),await readFile(new URL(url.pathname.slice(1),root)));}
for(const match of page.matchAll(/(?:href|src)="\.\/([^"#?]+)(?:[?#][^"]*)?"/g)){const name=match[1],asset=await fetch(base+name);assert.equal(asset.status,200,name);assert.deepEqual(Buffer.from(await asset.arrayBuffer()),await readFile(new URL(name,root)));}
const files=await build(undefined,out);for(const name of ['learn.html','learning-route.mjs','learning-route-ui.mjs','learning-route.css']){assert.ok(files.includes(name));assert.deepEqual(await readFile(join(out,name)),await readFile(new URL(name,root)));}
const neural=await(await fetch(base+'neural.html')).text();for(const id of ['first-lesson','gradient-lesson','generalization-lesson','field'])assert.ok(neural.includes(`id="${id}"`));
diff --git a/tests/delivery/learning-route-loading.test.mjs b/tests/delivery/learning-route-loading.test.mjs
new file mode 100644
index 0000000..68722f9
--- /dev/null
+++ b/tests/delivery/learning-route-loading.test.mjs
@@ -0,0 +1,22 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import {execFileSync} from 'node:child_process';
+
+for(const name of ['learning-route.mjs','learning-tool.mjs']){
+ test(`learning route loads ${name} once across play, trial comparison and GenAI return`,()=>{
+ const entry=new URL('../../dist/learning-route-ui.mjs',import.meta.url).href;
+ // Observe actual module instantiation in a fresh process. Different query
+ // strings must not make the built page load the same engine more than once.
+ const output=execFileSync(process.execPath,['--input-type=module','-e',`
+ import {registerHooks} from 'node:module';
+ registerHooks({load(url,context,next){
+ const result=next(url,context);
+ if(new URL(url).pathname.split('/').at(-1)===${JSON.stringify(name)})console.log(JSON.stringify(url));
+ return result;
+ }});
+ await import(${JSON.stringify(entry)});
+ `],{encoding:'utf8'});
+ const loaded=output.trim().split('\n').filter(Boolean).map(line=>JSON.parse(line));
+ assert.equal(loaded.length,1,`${name}: expected one actual load, got ${loaded.join(', ')}`);
+ });
+}