一、问题(本轮实测)
`draw-ui` 与 `oil-motion` 目录里**各自带一个内嵌 `.git`** ⇒ 上一次提交把它们记成了 **gitlink(子模块指针)**
⇒ 仓库里只存了一个不属于任何远端的 commit id,**别人克隆下来这两份是空的** ✗(`git status` 显示 ` m draw-ui` / ` m oil-motion` = 子模块内容有改动)。
二、处置(可回退)
· 把两处的 `.git` **挪走**(⛔ 不是删除)⇒ `归档/内嵌git-20261008/{draw-ui,oil-motion}.git`;
· `git rm --cached` 掉那两个 gitlink,再 `git add` 两个目录 ⇒ **按正常文件入库**(内容才真的进仓库)。
三、副作用(如实记)
挪走 `.git` 后,这两个技能**不能再原地 `git pull` 取上游更新**(要更新得重新拉一份覆盖);
如需恢复其本地仓库,把 `归档/内嵌git-20261008/` 里的 `.git` 挪回原处即可。
39 lines
2.7 KiB
TypeScript
39 lines
2.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { execFile } from 'node:child_process';
|
|
import { parseBindings, prepareCommand } from '../src/run.ts';
|
|
|
|
async function fixture() {
|
|
const dir = await mkdtemp(path.join(tmpdir(), 'credential-run-'));
|
|
const files = [path.join(dir, 'first.json'), path.join(dir, 'second.json')];
|
|
await Promise.all(files.map((file, i) => writeFile(file, JSON.stringify({ version: 1, id: 'sample-skill', label: '服务', credential: 'sample/key-' + i }))));
|
|
return { dir, files, cleanup: () => rm(dir, { recursive: true, force: true }) };
|
|
}
|
|
test('多个 key 同时注入一个真实子进程,命令参数不包含值', async t => {
|
|
const f = await fixture(); t.after(f.cleanup);
|
|
const plan = await prepareCommand(['--manifest', f.files[0], '--env', 'FIRST_API_KEY', '--manifest', f.files[1], '--env', 'SECOND_API_KEY', '--',
|
|
process.execPath, '-e', 'process.exit(process.env.FIRST_API_KEY && process.env.SECOND_API_KEY && process.env.FIRST_API_KEY !== process.env.SECOND_API_KEY ? 0 : 1)'],
|
|
async ref => ref.endsWith('0') ? 'FAKE_FIRST_VALUE' : 'FAKE_SECOND_VALUE');
|
|
assert.equal(plan.env.FIRST_API_KEY, 'FAKE_FIRST_VALUE'); assert.equal(plan.env.SECOND_API_KEY, 'FAKE_SECOND_VALUE');
|
|
assert.equal(JSON.stringify(plan.args).includes('FAKE_'), false);
|
|
await new Promise<void>((resolve, reject) => execFile(plan.command, plan.args, { env: plan.env }, error => error ? reject(error) : resolve()));
|
|
});
|
|
test('任一 key 缺失或后端失败,不返回可启动的命令,也不修改父环境', async t => {
|
|
const f = await fixture(); t.after(f.cleanup);
|
|
const args = ['--manifest', f.files[0], '--env', 'FIRST_API_KEY', '--manifest', f.files[1], '--env', 'SECOND_API_KEY', '--', 'unused'];
|
|
const base = { KEEP: 'unchanged' };
|
|
await assert.rejects(prepareCommand(args, async ref => ref.endsWith('0') ? 'FAKE_FIRST_VALUE' : undefined, base), /未配置/);
|
|
await assert.rejects(prepareCommand(args, async () => { throw Error('FAKE_VALUE_MUST_NOT_LEAK'); }, base),
|
|
error => error instanceof Error && !error.message.includes('FAKE_'));
|
|
assert.deepEqual(base, { KEEP: 'unchanged' });
|
|
});
|
|
test('拒绝重复变量和不完整绑定,兼容单 key 的原入口', () => {
|
|
assert.throws(() => parseBindings(['--env', 'DUP_KEY', '--env', 'DUP_KEY', '--', 'unused']), /重复/);
|
|
assert.throws(() => parseBindings(['--manifest', 'a.json', '--manifest', 'b.json', '--env', 'A_KEY', '--', 'unused']));
|
|
assert.throws(() => parseBindings(['--env', 'HOME', '--', 'unused']));
|
|
assert.equal(parseBindings(['--env', 'SERVICE_API_KEY', '--', 'program', 'arg']).bindings.length, 1);
|
|
});
|