oficina / docs Public

Docs import: US English catalog; reader limits with replay headroom.

The catalog guard (TestTheCatalogIsWrittenInUSEnglish, remote CI on
9adc935) caught colours/centred/colour: now colors/centered/color.

The full gate's parallel load made replaying an import at the reader's
old limit (2 MiB of text in 40,000 runs) overrun the 1 s guest-call
limit that every later opening of the document replays under; isolated
it took 0.2 s, which is not headroom enough. The reader now stops at
5,000 blocks, 10,000 runs and 512 KiB of text (still about a 300-page
document), a quarter of the work, and the builder test holds the new
limit to the same budget. The too-large message says the new limits.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev b805ac42679bcd296e03754ed0f855c922d87928 parent 9adc935
4 files changed, +16 −18
  • internal/core/build_test.go +6 −8
  • internal/docs/render.go +4 −4
  • internal/docx/read.go +3 −3
  • internal/docx/read_test.go +3 −3

CI passed — run details

diff --git a/internal/core/build_test.go b/internal/core/build_test.go
index 79e2572..bf5eb91 100644
--- a/internal/core/build_test.go
+++ b/internal/core/build_test.go
@@ -112,19 +112,17 @@ func TestBuildAtTheReadersLimitFitsTheCallTimeout(t *testing.T) {
}
defer rt.Close(ctx)
- // 10,000 blocks of four runs, 52 bytes each: 2 MiB of text.
+ // 5,000 blocks of two runs, 52 bytes each: about 508 KiB of text in
+ // 10,000 runs.
text := make([]byte, 52)
for i := range text {
text[i] = 'a' + byte(i%26)
}
- blocks := make([]core.BuildBlock, 10_000)
+ blocks := make([]core.BuildBlock, 5_000)
for i := range blocks {
- for r := 0; r < 4; r++ {
- run := core.BuildRun{Text: string(text)}
- if r%2 == 1 {
- run.Marks = []string{"strong", "font_sans", "size_14"}
- }
- blocks[i].Runs = append(blocks[i].Runs, run)
+ blocks[i].Runs = []core.BuildRun{
+ {Text: string(text)},
+ {Marks: []string{"strong", "font_sans", "size_14"}, Text: string(text)},
}
}
ops, err := core.EncodeBuild(blocks)
diff --git a/internal/docs/render.go b/internal/docs/render.go
index 46a38b0..1a6325a 100644
--- a/internal/docs/render.go
+++ b/internal/docs/render.go
@@ -321,13 +321,13 @@ var Catalog = rastrillo.Catalog{
"docs.list.import": "Import…",
"docs.import.title": "Import a Word document",
"docs.import.intro": "Choose a .docx file. Docs makes a new, editable copy; the file itself is not changed or kept.",
- "docs.import.fidelity": "An import brings in paragraph text, headings, bold and italic, and the fonts and sizes Docs has. Headings take Docs' own heading look. Lists and tables become plain paragraphs, links keep their text, and spacing, indentation, colours, images, comments, footnotes, headers and footers are left out. Docs lists what it noticed afterwards.",
+ "docs.import.fidelity": "An import brings in paragraph text, headings, bold and italic, and the fonts and sizes Docs has. Headings take Docs' own heading look. Lists and tables become plain paragraphs, links keep their text, and spacing, indentation, colors, images, comments, footnotes, headers and footers are left out. Docs lists what it noticed afterwards.",
"docs.import.file": "Word document (.docx)",
"docs.import.submit": "Import",
"docs.import.error.nofile": "Choose a .docx file to import.",
"docs.import.error.notword": "That file is not a Word document Docs can read. Choose a .docx file, or download the document from Google Docs as Microsoft Word (.docx).",
"docs.import.error.damaged": "That Word document looks damaged, so nothing was imported. Try saving it again from the program that made it.",
- "docs.import.error.toolarge": "That document is too large to import. The limit is a 10 MB file holding up to 10,000 paragraphs.",
+ "docs.import.error.toolarge": "That document is too large to import. The limit is a 10 MB file holding up to 5,000 paragraphs and about 500 KB of text.",
"docs.import.error.empty": "That document has no text Docs can import, so nothing was created.",
"docs.import.error.busy": "Docs is busy importing other documents. Try again in a moment.",
"docs.import.error.failed": "The import did not finish, and nothing was created. Try again.",
@@ -355,8 +355,8 @@ var Catalog = rastrillo.Catalog{
"docs.import.report.subtitle_as_paragraph": "Subtitles became ordinary paragraphs: {count}.",
"docs.import.report.font_substituted": "Text in fonts Docs does not have is in the default font instead: {count} runs.",
"docs.import.report.size_dropped": "Text in sizes Docs does not offer is at the default size instead: {count} runs.",
- "docs.import.report.formatting_lost": "Underline, strikethrough, colour, highlight, superscript, subscript and capitals were left out: {count} runs.",
- "docs.import.report.alignment_lost": "Centred and right-aligned paragraphs are left-aligned: {count}.",
+ "docs.import.report.formatting_lost": "Underline, strikethrough, color, highlight, superscript, subscript and capitals were left out: {count} runs.",
+ "docs.import.report.alignment_lost": "Centered and right-aligned paragraphs are left-aligned: {count}.",
"docs.import.report.tab_as_space": "Tabs became spaces: {count}.",
"docs.import.report.line_break_split": "Line breaks became new paragraphs: {count}.",
"docs.import.report.page_break_split": "Page and column breaks became new paragraphs: {count}.",
diff --git a/internal/docx/read.go b/internal/docx/read.go
index a1d2562..012aa3c 100644
--- a/internal/docx/read.go
+++ b/internal/docx/read.go
@@ -91,9 +91,9 @@ const (
maxPartBytes = 32 << 20
maxTotalBytes = 64 << 20
maxDepth = 256
- maxBlocks = 10_000
- maxRuns = 40_000
- maxText = 2 << 20
+ maxBlocks = 5_000
+ maxRuns = 10_000
+ maxText = 512 << 10
// maxLocations is how many paragraph numbers one report item keeps;
// its Count is still exact.
diff --git a/internal/docx/read_test.go b/internal/docx/read_test.go
index 16593b1..93b6932 100644
--- a/internal/docx/read_test.go
+++ b/internal/docx/read_test.go
@@ -408,9 +408,9 @@ func TestImportRefusals(t *testing.T) {
{"too many entries", zipOf(t, many), docx.ErrTooLarge},
{"nothing but empty paragraphs", zipOf(t, doc(para("", "")+para("", `<w:r><w:drawing/></w:r>`))), docx.ErrEmpty},
{"only deleted text", zipOf(t, doc(para("", `<w:del><w:r><w:delText>x</w:delText></w:r></w:del>`))), docx.ErrEmpty},
- {"too many blocks", zipOf(t, doc(strings.Repeat(para("", run("", "x")), 10_001))), docx.ErrTooLarge},
- {"too much text", zipOf(t, doc(para("", run("", strings.Repeat("x", 2<<20+1))))), docx.ErrTooLarge},
- {"too many runs", zipOf(t, doc(para("", strings.Repeat(run("", "x"), 40_001)))), docx.ErrTooLarge},
+ {"too many blocks", zipOf(t, doc(strings.Repeat(para("", run("", "x")), 5_001))), docx.ErrTooLarge},
+ {"too much text", zipOf(t, doc(para("", run("", strings.Repeat("x", 512<<10+1))))), docx.ErrTooLarge},
+ {"too many runs", zipOf(t, doc(para("", strings.Repeat(run("", "x"), 10_001)))), docx.ErrTooLarge},
}
for _, c := range cases {
if _, err := docx.Import(c.data); !errors.Is(err, c.want) {