chore: sync with upstream ae2c063 + update zh translations

This commit is contained in:
xuxiang
2026-01-31 18:22:06 +08:00
parent 6c531eb17b
commit b1d03833b9
30 changed files with 1694 additions and 516 deletions

View File

@@ -8,7 +8,7 @@ const assert = require('assert');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { execSync, spawn } = require('child_process');
const { spawn } = require('child_process');
// Test helper
function test(name, fn) {
@@ -113,14 +113,19 @@ async function runTests() {
// Run the script
await runScript(path.join(scriptsDir, 'session-end.js'));
// Check if session file was created (default session ID)
// Check if session file was created
// Note: Without CLAUDE_SESSION_ID, falls back to project name (not 'default')
// Use local time to match the script's getDateString() function
const sessionsDir = path.join(os.homedir(), '.claude', 'sessions');
const now = new Date();
const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
const sessionFile = path.join(sessionsDir, `${today}-default-session.tmp`);
assert.ok(fs.existsSync(sessionFile), 'Session file should exist');
// Get the expected session ID (project name fallback)
const utils = require('../../scripts/lib/utils');
const expectedId = utils.getSessionIdShort();
const sessionFile = path.join(sessionsDir, `${today}-${expectedId}-session.tmp`);
assert.ok(fs.existsSync(sessionFile), `Session file should exist: ${sessionFile}`);
})) passed++; else failed++;
if (await asyncTest('includes session ID in filename', async () => {
@@ -296,7 +301,7 @@ async function runTests() {
}
};
for (const [eventType, hookArray] of Object.entries(hooks.hooks)) {
for (const [, hookArray] of Object.entries(hooks.hooks)) {
checkHooks(hookArray);
}
})) passed++; else failed++;
@@ -320,11 +325,27 @@ async function runTests() {
}
};
for (const [eventType, hookArray] of Object.entries(hooks.hooks)) {
for (const [, hookArray] of Object.entries(hooks.hooks)) {
checkHooks(hookArray);
}
})) passed++; else failed++;
// plugin.json validation
console.log('\nplugin.json Validation:');
if (test('plugin.json does NOT have explicit hooks declaration', () => {
// Claude Code automatically loads hooks/hooks.json by convention.
// Explicitly declaring it in plugin.json causes a duplicate detection error.
// See: https://github.com/affaan-m/everything-claude-code/issues/103
const pluginPath = path.join(__dirname, '..', '..', '.claude-plugin', 'plugin.json');
const plugin = JSON.parse(fs.readFileSync(pluginPath, 'utf8'));
assert.ok(
!plugin.hooks,
'plugin.json should NOT have "hooks" field - Claude Code auto-loads hooks/hooks.json'
);
})) passed++; else failed++;
// Summary
console.log('\n=== Test Results ===');
console.log(`Passed: ${passed}`);

View File

@@ -11,7 +11,6 @@ const os = require('os');
// Import the modules
const pm = require('../../scripts/lib/package-manager');
const utils = require('../../scripts/lib/utils');
// Test helper
function test(name, fn) {

View File

@@ -7,7 +7,6 @@
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const os = require('os');
// Import the module
const utils = require('../../scripts/lib/utils');
@@ -106,58 +105,52 @@ function runTests() {
assert.ok(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dt), `Expected YYYY-MM-DD HH:MM:SS, got ${dt}`);
})) passed++; else failed++;
// Project name tests
console.log('\nProject Name Functions:');
if (test('getGitRepoName returns string or null', () => {
const repoName = utils.getGitRepoName();
assert.ok(repoName === null || typeof repoName === 'string');
})) passed++; else failed++;
if (test('getProjectName returns non-empty string', () => {
const name = utils.getProjectName();
assert.ok(name && name.length > 0);
})) passed++; else failed++;
// Session ID tests
console.log('\nSession ID Functions:');
if (test('getSessionIdShort returns default when no env var', () => {
const originalEnv = process.env.CLAUDE_SESSION_ID;
if (test('getSessionIdShort falls back to project name', () => {
const original = process.env.CLAUDE_SESSION_ID;
delete process.env.CLAUDE_SESSION_ID;
try {
const shortId = utils.getSessionIdShort();
assert.strictEqual(shortId, 'default');
assert.strictEqual(shortId, utils.getProjectName());
} finally {
if (originalEnv) process.env.CLAUDE_SESSION_ID = originalEnv;
if (original) process.env.CLAUDE_SESSION_ID = original;
}
})) passed++; else failed++;
if (test('getSessionIdShort returns last 8 characters', () => {
const originalEnv = process.env.CLAUDE_SESSION_ID;
const original = process.env.CLAUDE_SESSION_ID;
process.env.CLAUDE_SESSION_ID = 'test-session-abc12345';
try {
const shortId = utils.getSessionIdShort();
assert.strictEqual(shortId, 'abc12345');
assert.strictEqual(utils.getSessionIdShort(), 'abc12345');
} finally {
if (originalEnv) {
process.env.CLAUDE_SESSION_ID = originalEnv;
} else {
delete process.env.CLAUDE_SESSION_ID;
}
}
})) passed++; else failed++;
if (test('getSessionIdShort uses custom fallback', () => {
const originalEnv = process.env.CLAUDE_SESSION_ID;
delete process.env.CLAUDE_SESSION_ID;
try {
const shortId = utils.getSessionIdShort('custom');
assert.strictEqual(shortId, 'custom');
} finally {
if (originalEnv) process.env.CLAUDE_SESSION_ID = originalEnv;
if (original) process.env.CLAUDE_SESSION_ID = original;
else delete process.env.CLAUDE_SESSION_ID;
}
})) passed++; else failed++;
if (test('getSessionIdShort handles short session IDs', () => {
const originalEnv = process.env.CLAUDE_SESSION_ID;
const original = process.env.CLAUDE_SESSION_ID;
process.env.CLAUDE_SESSION_ID = 'short';
try {
const shortId = utils.getSessionIdShort();
assert.strictEqual(shortId, 'short');
assert.strictEqual(utils.getSessionIdShort(), 'short');
} finally {
if (originalEnv) {
process.env.CLAUDE_SESSION_ID = originalEnv;
} else {
delete process.env.CLAUDE_SESSION_ID;
}
if (original) process.env.CLAUDE_SESSION_ID = original;
else delete process.env.CLAUDE_SESSION_ID;
}
})) passed++; else failed++;