Skip to content

Commit 09ebfcb

Browse files
authored
feat(document-api): lists namespace (#2223)
* feat(document-api): lists namespace * fix(cli): use pre-separated fixture for continuePrevious/join conformance tests
1 parent 2f5899d commit 09ebfcb

76 files changed

Lines changed: 8000 additions & 921 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/cli/scripts/export-sdk-contract.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,20 @@ const INTENT_NAMES = {
111111
'doc.lists.list': 'list_lists',
112112
'doc.lists.get': 'get_list',
113113
'doc.lists.insert': 'insert_list',
114-
'doc.lists.setType': 'set_list_type',
115114
'doc.lists.indent': 'indent_list',
116115
'doc.lists.outdent': 'outdent_list',
117-
'doc.lists.restart': 'restart_list_numbering',
118-
'doc.lists.exit': 'exit_list',
116+
'doc.lists.create': 'create_list',
117+
'doc.lists.attach': 'attach_to_list',
118+
'doc.lists.detach': 'detach_from_list',
119+
'doc.lists.join': 'join_lists',
120+
'doc.lists.canJoin': 'can_join_lists',
121+
'doc.lists.separate': 'separate_list',
122+
'doc.lists.setLevel': 'set_list_level',
123+
'doc.lists.setValue': 'set_list_value',
124+
'doc.lists.continuePrevious': 'continue_previous_list',
125+
'doc.lists.canContinuePrevious': 'can_continue_previous_list',
126+
'doc.lists.setLevelRestart': 'set_list_level_restart',
127+
'doc.lists.convertToText': 'convert_list_to_text',
119128
'doc.comments.create': 'create_comment',
120129
'doc.comments.patch': 'patch_comment',
121130
'doc.comments.delete': 'delete_comment',

apps/cli/src/__tests__/cli.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,21 @@ async function runCli(args: string[], stdinBytes?: Uint8Array): Promise<RunResul
5151
let stdout = '';
5252
let stderr = '';
5353

54-
const code = await run(args, {
55-
stdout(message: string) {
56-
stdout += message;
57-
},
58-
stderr(message: string) {
59-
stderr += message;
60-
},
61-
async readStdinBytes() {
62-
return stdinBytes ?? new Uint8Array();
54+
const code = await run(
55+
args,
56+
{
57+
stdout(message: string) {
58+
stdout += message;
59+
},
60+
stderr(message: string) {
61+
stderr += message;
62+
},
63+
async readStdinBytes() {
64+
return stdinBytes ?? new Uint8Array();
65+
},
6366
},
64-
});
67+
{ stateDir: STATE_DIR },
68+
);
6569

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

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

158161
afterAll(async () => {
159162
await rm(TEST_DIR, { recursive: true, force: true });
160-
delete process.env.SUPERDOC_CLI_STATE_DIR;
161163
});
162164

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

1175-
test('lists set-type tracked mode maps to TRACK_CHANGE_COMMAND_UNAVAILABLE', async () => {
1176-
const source = join(TEST_DIR, 'lists-set-type-source.docx');
1177-
const out = join(TEST_DIR, 'lists-set-type-out.docx');
1177+
test('lists detach tracked mode maps to TRACK_CHANGE_COMMAND_UNAVAILABLE', async () => {
1178+
const source = join(TEST_DIR, 'lists-detach-source.docx');
1179+
const out = join(TEST_DIR, 'lists-detach-out.docx');
11781180
await copyFile(LIST_SAMPLE_DOC, source);
11791181

11801182
const target = await firstListItemAddress(['lists', 'list', source, '--limit', '1']);
1181-
const setTypeResult = await runCli([
1183+
const detachResult = await runCli([
11821184
'lists',
1183-
'set-type',
1185+
'detach',
11841186
source,
11851187
'--target-json',
11861188
JSON.stringify(target),
1187-
'--kind',
1188-
'bullet',
11891189
'--change-mode',
11901190
'tracked',
11911191
'--out',
11921192
out,
11931193
]);
11941194

1195-
expect(setTypeResult.code).toBe(1);
1196-
const envelope = parseJsonOutput<ErrorEnvelope>(setTypeResult);
1195+
expect(detachResult.code).toBe(1);
1196+
const envelope = parseJsonOutput<ErrorEnvelope>(detachResult);
11971197
expect(envelope.error.code).toBe('TRACK_CHANGE_COMMAND_UNAVAILABLE');
11981198
});
11991199

apps/cli/src/__tests__/conformance/harness.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { copyFile, mkdtemp, mkdir, rm } from 'node:fs/promises';
22
import { tmpdir } from 'node:os';
33
import path from 'node:path';
44
import { run } from '../../index';
5-
import { resolveListDocFixture, resolveSourceDocFixture, resolveTocDocFixture } from '../fixtures';
5+
import {
6+
resolveListDocFixture,
7+
resolvePreSeparatedListFixture,
8+
resolveSourceDocFixture,
9+
resolveTocDocFixture,
10+
} from '../fixtures';
611

712
type RunResult = {
813
code: number;
@@ -125,6 +130,12 @@ export class ConformanceHarness {
125130
return filePath;
126131
}
127132

133+
async copyPreSeparatedListDoc(label: string): Promise<string> {
134+
const filePath = path.join(this.docsDir, `${this.nextId()}-${label}.docx`);
135+
await copyFile(await resolvePreSeparatedListFixture(), filePath);
136+
return filePath;
137+
}
138+
128139
async copyTocFixtureDoc(label: string, stateDir: string): Promise<string> {
129140
const filePath = path.join(this.docsDir, `${this.nextId()}-${label}.docx`);
130141

@@ -164,13 +175,11 @@ export class ConformanceHarness {
164175
stateDir: string,
165176
stdinBytes?: Uint8Array,
166177
): Promise<{ result: RunResult; envelope: CommandEnvelope }> {
167-
const previousStateDir = process.env.SUPERDOC_CLI_STATE_DIR;
168-
process.env.SUPERDOC_CLI_STATE_DIR = stateDir;
169-
170178
let stdout = '';
171179
let stderr = '';
172-
try {
173-
const code = await run(args, {
180+
const code = await run(
181+
args,
182+
{
174183
stdout(message: string) {
175184
stdout += message;
176185
},
@@ -180,17 +189,12 @@ export class ConformanceHarness {
180189
async readStdinBytes() {
181190
return stdinBytes ?? new Uint8Array();
182191
},
183-
});
184-
185-
const result: RunResult = { code, stdout, stderr };
186-
return { result, envelope: parseEnvelope(result) };
187-
} finally {
188-
if (previousStateDir == null) {
189-
delete process.env.SUPERDOC_CLI_STATE_DIR;
190-
} else {
191-
process.env.SUPERDOC_CLI_STATE_DIR = previousStateDir;
192-
}
193-
}
192+
},
193+
{ stateDir },
194+
);
195+
196+
const result: RunResult = { code, stdout, stderr };
197+
return { result, envelope: parseEnvelope(result) };
194198
}
195199

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

0 commit comments

Comments
 (0)