fix: skip occupied snapshot paths without overflowing

This commit is contained in:
Eneko Ruiz
2026-10-11 16:29:15 +02:00
parent acb75bc1ed
commit 6d8e69df52
2 changed files with 25 additions and 2 deletions
+9 -2
View File
@@ -163,8 +163,15 @@ function createVersion(skillPath, options = {}) {
ensureSkillVersioning(skillPath);
const versions = listVersions(skillPath);
const nextVersion = versions.length === 0 ? 1 : versions[versions.length - 1].version + 1;
const snapshotPath = path.join(getVersionsDir(skillPath), `v${nextVersion}.md`);
let nextVersion = versions.length === 0 ? 1 : versions[versions.length - 1].version + 1;
let snapshotPath = path.join(getVersionsDir(skillPath), `v${nextVersion}.md`);
while (Number.isSafeInteger(nextVersion) && fs.existsSync(snapshotPath)) {
nextVersion += 1;
snapshotPath = path.join(getVersionsDir(skillPath), `v${nextVersion}.md`);
}
if (!Number.isSafeInteger(nextVersion)) {
throw new Error('Skill version exceeds the safe integer range');
}
const skillContent = fs.readFileSync(skillFilePath, 'utf8');
const createdAt = options.timestamp || new Date().toISOString();
+16
View File
@@ -221,8 +221,24 @@ function runTests() {
);
assert.strictEqual(versioning.getCurrentVersion(skillDir), 1);
assert.ok(fs.statSync(snapshotDirectory).isDirectory());
for (const version of [2, 3]) {
fs.mkdirSync(path.join(versioning.getVersionsDir(skillDir), `v${version}.md`));
}
assert.strictEqual(versioning.createVersion(skillDir).version, 4);
assert.deepStrictEqual(versioning.listVersions(skillDir).map(entry => entry.version), [1, 4]);
for (const version of [2, 3]) {
assert.ok(fs.statSync(path.join(versioning.getVersionsDir(skillDir), `v${version}.md`)).isDirectory());
}
assert.strictEqual(versioning.getCurrentVersion(path.join(fixtureRoot, 'missing-skill')), 0);
assert.throws(() => versioning.createVersion(snapshotDirectory), /Skill file not found/);
const oversizedSnapshot = path.join(versioning.getVersionsDir(skillDir), 'v9007199254740992.md');
fs.writeFileSync(oversizedSnapshot, 'Preserve this snapshot');
const overflow = spawnSync(process.execPath, [
'-e', 'require("assert").throws(() => require(process.argv[1]).createVersion(process.argv[2]), /safe integer/)',
require.resolve('../../scripts/lib/skill-evolution/versioning'), skillDir,
], { encoding: 'utf8', timeout: 10000 });
assert.strictEqual(overflow.status, 0, overflow.error?.message || overflow.stderr);
assert.strictEqual(fs.readFileSync(oversizedSnapshot, 'utf8'), 'Preserve this snapshot');
} finally {
cleanupTempDir(fixtureRoot);
}