chore: 新增项目规则文档、构建别名及忽略规则

添加 AGENTS.md 项目规则文件,涵盖语言与工具链、模块设计、
Git 提交规范及验证流程等内容。

变更要点:
- .cargo/config.toml 新增 xtask 命令别名
- .gitignore 忽略运行时地图缓存、接收器配置文件、
  构建锁文件及本地 docs/ 目录
- 新增 AGENTS.md 定义项目编码、提交与审查规则
```
This commit is contained in:
2026-10-21 16:23:47 +08:00
parent 19d4b6de29
commit 7d2e37a0ef
75 changed files with 13196 additions and 2939 deletions
+20 -17
View File
@@ -1,18 +1,21 @@
import fs from 'node:fs';
import vm from 'node:vm';
// Regression tests against the actual Rust/Wasm frontend, not copied JavaScript functions.
import {mkdtemp} from 'node:fs/promises';
import {tmpdir} from 'node:os';
import path from 'node:path';
import {spawn} from 'node:child_process';
import {createRequire} from 'node:module';
import assert from 'node:assert/strict';
const source=fs.readFileSync(new URL('../registry/web/app.js',import.meta.url),'utf8');
const elements=new Map();
const $=id=>{if(!elements.has(id))elements.set(id,{textContent:'',value:'',disabled:false,checked:false,classList:{toggle(){},remove(){}},replaceChildren(){},append(){}});return elements.get(id);};
const context={$,currentPage:1,totalPages:3,listRequestId:0,selectedIds:new Set(),listedRecords:[],document:{createElement(){throw Error('unexpected record rendering');}},updateSelectionControls(){},fetch:async()=>{throw Error('network failure');}};
vm.createContext(context);
vm.runInContext(source.slice(source.indexOf('function updatePageButtons'),source.indexOf('function archiveStatus')),context);
vm.runInContext(source.slice(source.indexOf('async function loadRecords'),source.indexOf("$('register-form')")),context);
await assert.rejects(context.loadRecords(2),/network failure/);assert.equal(context.currentPage,1);assert.equal($('next-page').disabled,false);
let calls=[];
context.fetch=async url=>{calls.push(url);return{ok:true,json:async()=>({records:[],page:2,pageSize:20,total:45,totalPages:3})};};
await context.loadRecords(2);assert.equal(context.currentPage,2);assert.match(calls[0],/page=2&/);
let releaseOld;context.fetch=()=>new Promise(resolve=>releaseOld=resolve);const older=context.loadRecords(1);
context.fetch=async()=>({ok:true,json:async()=>({records:[],total:45,totalPages:3})});await context.loadRecords(3);
releaseOld({ok:true,json:async()=>({records:[],total:45,totalPages:3})});await older;assert.equal(context.currentPage,3);
console.log('PASS: failed pagination retains page, successful page commits, stale response ignored');
const require=createRequire(import.meta.url);const {chromium}=require('playwright');
const base='http://127.0.0.1:8787';let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(1000)});occupied=true;}catch{}if(occupied)throw Error('8787 occupied');
const root=await mkdtemp(path.join(tmpdir(),'RID-pagination-'));
const child=spawn(process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe',['--data-root',root],{windowsHide:true,stdio:['ignore','pipe','pipe']});let output='',failure;child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>failure=e);let browser;
try{
let ready=false;for(let i=0;i<150;i++){if(failure||child.exitCode!==null)throw Error(output||String(failure));try{if((await fetch(base)).ok){ready=true;break;}}catch{}await new Promise(r=>setTimeout(r,100));}assert.ok(ready);
browser=await chromium.launch({headless:true,executablePath:process.env.RID_BROWSER_PATH||'C:/Program Files/Google/Chrome/Application/chrome.exe'});const page=await browser.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));let fail=false;
await page.route('**/api/records?**',async route=>{const u=new URL(route.request().url());if(u.searchParams.get('q')==='old')await new Promise(r=>setTimeout(r,800));if(fail){fail=false;await route.fulfill({status:500,contentType:'application/json',body:JSON.stringify({error:'network failure'})});return;}await route.fulfill({status:200,contentType:'application/json',body:JSON.stringify({records:[],page:Number(u.searchParams.get('page')),pageSize:20,total:u.searchParams.get('q')==='old'?999:45,totalPages:3})});});
await page.goto(base);await page.locator('#page-status').filter({hasText:'第 1 / 3 页'}).waitFor();
fail=true;await page.click('#next-page');await page.locator('#history-message').filter({hasText:'network failure'}).waitFor();assert.match(await page.locator('#page-status').textContent(),/第 1/);assert.equal(await page.locator('#next-page').isEnabled(),true);
await page.click('#next-page');await page.locator('#page-status').filter({hasText:'第 2 / 3 页'}).waitFor();
await page.fill('#history-query','old');await page.waitForRequest(r=>r.url().includes('q=old'));await page.fill('#history-query','new');await page.locator('#page-status').filter({hasText:'共 45 条'}).waitFor();await page.waitForTimeout(1000);assert.ok(!(await page.locator('#page-status').textContent()).includes('999'));assert.deepEqual(errors,[]);
console.log(JSON.stringify({status:'PASS',root,scenarios:['failed page retains index','successful page commits','old search response ignored','actual Rust/Wasm frontend']}));
}finally{if(browser)await browser.close();if(child.exitCode===null&&!failure){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}}