Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions apps/cli/scripts/export-sdk-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,20 @@ const INTENT_NAMES = {
'doc.lists.list': 'list_lists',
'doc.lists.get': 'get_list',
'doc.lists.insert': 'insert_list',
'doc.lists.setType': 'set_list_type',
'doc.lists.indent': 'indent_list',
'doc.lists.outdent': 'outdent_list',
'doc.lists.restart': 'restart_list_numbering',
'doc.lists.exit': 'exit_list',
'doc.lists.create': 'create_list',
'doc.lists.attach': 'attach_to_list',
'doc.lists.detach': 'detach_from_list',
'doc.lists.join': 'join_lists',
'doc.lists.canJoin': 'can_join_lists',
'doc.lists.separate': 'separate_list',
'doc.lists.setLevel': 'set_list_level',
'doc.lists.setValue': 'set_list_value',
'doc.lists.continuePrevious': 'continue_previous_list',
'doc.lists.canContinuePrevious': 'can_continue_previous_list',
'doc.lists.setLevelRestart': 'set_list_level_restart',
'doc.lists.convertToText': 'convert_list_to_text',
'doc.comments.create': 'create_comment',
'doc.comments.patch': 'patch_comment',
'doc.comments.delete': 'delete_comment',
Expand Down
42 changes: 21 additions & 21 deletions apps/cli/src/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ async function runCli(args: string[], stdinBytes?: Uint8Array): Promise<RunResul
let stdout = '';
let stderr = '';

const code = await run(args, {
stdout(message: string) {
stdout += message;
},
stderr(message: string) {
stderr += message;
},
async readStdinBytes() {
return stdinBytes ?? new Uint8Array();
const code = await run(
args,
{
stdout(message: string) {
stdout += message;
},
stderr(message: string) {
stderr += message;
},
async readStdinBytes() {
return stdinBytes ?? new Uint8Array();
},
},
});
{ stateDir: STATE_DIR },
);

return { code, stdout, stderr };
}
Expand Down Expand Up @@ -145,7 +149,6 @@ async function firstListItemAddress(args: string[]): Promise<ListItemAddress> {

describe('superdoc CLI', () => {
beforeAll(async () => {
process.env.SUPERDOC_CLI_STATE_DIR = STATE_DIR;
await mkdir(TEST_DIR, { recursive: true });
await copyFile(await resolveSourceDocFixture(), SAMPLE_DOC);
await copyFile(await resolveListDocFixture(), LIST_SAMPLE_DOC);
Expand All @@ -157,7 +160,6 @@ describe('superdoc CLI', () => {

afterAll(async () => {
await rm(TEST_DIR, { recursive: true, force: true });
delete process.env.SUPERDOC_CLI_STATE_DIR;
});

test('status returns inactive when no document is open', async () => {
Expand Down Expand Up @@ -1172,28 +1174,26 @@ describe('superdoc CLI', () => {
expect(closeResult.code).toBe(0);
});

test('lists set-type tracked mode maps to TRACK_CHANGE_COMMAND_UNAVAILABLE', async () => {
const source = join(TEST_DIR, 'lists-set-type-source.docx');
const out = join(TEST_DIR, 'lists-set-type-out.docx');
test('lists detach tracked mode maps to TRACK_CHANGE_COMMAND_UNAVAILABLE', async () => {
const source = join(TEST_DIR, 'lists-detach-source.docx');
const out = join(TEST_DIR, 'lists-detach-out.docx');
await copyFile(LIST_SAMPLE_DOC, source);

const target = await firstListItemAddress(['lists', 'list', source, '--limit', '1']);
const setTypeResult = await runCli([
const detachResult = await runCli([
'lists',
'set-type',
'detach',
source,
'--target-json',
JSON.stringify(target),
'--kind',
'bullet',
'--change-mode',
'tracked',
'--out',
out,
]);

expect(setTypeResult.code).toBe(1);
const envelope = parseJsonOutput<ErrorEnvelope>(setTypeResult);
expect(detachResult.code).toBe(1);
const envelope = parseJsonOutput<ErrorEnvelope>(detachResult);
expect(envelope.error.code).toBe('TRACK_CHANGE_COMMAND_UNAVAILABLE');
});

Expand Down
38 changes: 21 additions & 17 deletions apps/cli/src/__tests__/conformance/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { copyFile, mkdtemp, mkdir, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { run } from '../../index';
import { resolveListDocFixture, resolveSourceDocFixture, resolveTocDocFixture } from '../fixtures';
import {
resolveListDocFixture,
resolvePreSeparatedListFixture,
resolveSourceDocFixture,
resolveTocDocFixture,
} from '../fixtures';

type RunResult = {
code: number;
Expand Down Expand Up @@ -125,6 +130,12 @@ export class ConformanceHarness {
return filePath;
}

async copyPreSeparatedListDoc(label: string): Promise<string> {
const filePath = path.join(this.docsDir, `${this.nextId()}-${label}.docx`);
await copyFile(await resolvePreSeparatedListFixture(), filePath);
return filePath;
}

async copyTocFixtureDoc(label: string, stateDir: string): Promise<string> {
const filePath = path.join(this.docsDir, `${this.nextId()}-${label}.docx`);

Expand Down Expand Up @@ -164,13 +175,11 @@ export class ConformanceHarness {
stateDir: string,
stdinBytes?: Uint8Array,
): Promise<{ result: RunResult; envelope: CommandEnvelope }> {
const previousStateDir = process.env.SUPERDOC_CLI_STATE_DIR;
process.env.SUPERDOC_CLI_STATE_DIR = stateDir;

let stdout = '';
let stderr = '';
try {
const code = await run(args, {
const code = await run(
args,
{
stdout(message: string) {
stdout += message;
},
Expand All @@ -180,17 +189,12 @@ export class ConformanceHarness {
async readStdinBytes() {
return stdinBytes ?? new Uint8Array();
},
});

const result: RunResult = { code, stdout, stderr };
return { result, envelope: parseEnvelope(result) };
} finally {
if (previousStateDir == null) {
delete process.env.SUPERDOC_CLI_STATE_DIR;
} else {
process.env.SUPERDOC_CLI_STATE_DIR = previousStateDir;
}
}
},
{ stateDir },
);

const result: RunResult = { code, stdout, stderr };
return { result, envelope: parseEnvelope(result) };
}

async firstTextRange(docPath: string, stateDir: string, pattern = 'Wilde'): Promise<TextRangeAddress> {
Expand Down
Loading
Loading