140 lines
3.8 KiB
TypeScript
140 lines
3.8 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { mergeClawXSection, stripFirstRunSection } from '../../electron/utils/openclaw-workspace';
|
|
|
|
describe('stripFirstRunSection', () => {
|
|
it('removes the First Run section when it exists', () => {
|
|
const input = [
|
|
'# AGENTS.md',
|
|
'',
|
|
'Some preamble content.',
|
|
'',
|
|
'## First Run',
|
|
'',
|
|
"If `BOOTSTRAP.md` exists, that's your birth certificate. Follow it, figure out who you are, then delete it. You won't need it again.",
|
|
'',
|
|
'## Other Section',
|
|
'',
|
|
'Other content.',
|
|
].join('\n');
|
|
|
|
const result = stripFirstRunSection(input);
|
|
expect(result).not.toContain('## First Run');
|
|
expect(result).not.toContain('BOOTSTRAP.md');
|
|
expect(result).toContain('# AGENTS.md');
|
|
expect(result).toContain('Some preamble content.');
|
|
expect(result).toContain('## Other Section');
|
|
expect(result).toContain('Other content.');
|
|
});
|
|
|
|
it('returns content unchanged when no First Run section exists', () => {
|
|
const input = '# AGENTS.md\n\nSome content.\n';
|
|
expect(stripFirstRunSection(input)).toBe(input);
|
|
});
|
|
|
|
it('handles First Run section at end of file', () => {
|
|
const input = [
|
|
'# AGENTS.md',
|
|
'',
|
|
'## First Run',
|
|
'',
|
|
'Bootstrap text.',
|
|
'',
|
|
].join('\n');
|
|
|
|
const result = stripFirstRunSection(input);
|
|
expect(result).not.toContain('## First Run');
|
|
expect(result).not.toContain('Bootstrap text');
|
|
expect(result).toContain('# AGENTS.md');
|
|
});
|
|
|
|
it('does not collapse adjacent sections', () => {
|
|
const input = [
|
|
'## Section A',
|
|
'content a',
|
|
'',
|
|
'## First Run',
|
|
'',
|
|
'bootstrap text',
|
|
'',
|
|
'## Section B',
|
|
'content b',
|
|
].join('\n');
|
|
|
|
const result = stripFirstRunSection(input);
|
|
expect(result).toContain('## Section A');
|
|
expect(result).toContain('content a');
|
|
expect(result).toContain('## Section B');
|
|
expect(result).toContain('content b');
|
|
expect(result).not.toContain('## First Run');
|
|
});
|
|
|
|
it('does not remove sections with similar but different names', () => {
|
|
const input = [
|
|
'## First Run Setup',
|
|
'This should stay.',
|
|
'',
|
|
'## First Run',
|
|
'This should go.',
|
|
].join('\n');
|
|
|
|
const result = stripFirstRunSection(input);
|
|
expect(result).toContain('## First Run Setup');
|
|
expect(result).toContain('This should stay.');
|
|
expect(result).not.toContain('This should go.');
|
|
});
|
|
|
|
it('collapses triple blank lines left by removal', () => {
|
|
const input = [
|
|
'before',
|
|
'',
|
|
'',
|
|
'## First Run',
|
|
'',
|
|
'text',
|
|
'',
|
|
'',
|
|
'after',
|
|
].join('\n');
|
|
|
|
const result = stripFirstRunSection(input);
|
|
expect(result).not.toMatch(/\n{3,}/);
|
|
expect(result).toContain('before');
|
|
expect(result).toContain('after');
|
|
});
|
|
|
|
it('still changes AGENTS content when only First Run is removed', () => {
|
|
const section = [
|
|
'## ClawX Environment',
|
|
'',
|
|
'You are ClawX.',
|
|
].join('\n');
|
|
const original = [
|
|
'# AGENTS.md',
|
|
'',
|
|
'## First Run',
|
|
'',
|
|
"If `BOOTSTRAP.md` exists, that's your birth certificate. Follow it, figure out who you are, then delete it. You won't need it again.",
|
|
'',
|
|
'## Session Startup',
|
|
'',
|
|
'Read SOUL.md first.',
|
|
'',
|
|
'<!-- clawx:begin -->',
|
|
'## ClawX Environment',
|
|
'',
|
|
'You are ClawX.',
|
|
'<!-- clawx:end -->',
|
|
'',
|
|
].join('\n');
|
|
|
|
const stripped = stripFirstRunSection(original);
|
|
const merged = mergeClawXSection(stripped, section);
|
|
|
|
expect(merged).not.toBe(original);
|
|
expect(merged).not.toContain('## First Run');
|
|
expect(merged).toContain('## Session Startup');
|
|
expect(merged).toContain('<!-- clawx:begin -->');
|
|
expect(merged).toContain('<!-- clawx:end -->');
|
|
});
|
|
});
|