feat: package the shared reader for offline embedding (#16)
This commit is contained in:
1 parent
84f7636627
commit
23fa0306d1
12 files changed
+430
-62
No files matched your search
@@ -107,6 +107,66 @@ reject_import "$result_work/run.json" "$run_id" 'view.observation_stale'
|
||||
test ! -e "$result_work/project/out/view-sentinel.txt"
|
||||
echo 'Observation export: PASS (real CLI, selected run, stale/incomplete/truncated refusal, zero re-execution)'
|
||||
|
||||
# #16: embed both an analyzed document and ordinary Markdown through the same
|
||||
# release binary. No project sibling or blocked media should enter the package.
|
||||
embed_work="$result_work/embed"
|
||||
mkdir -p "$embed_work/project"
|
||||
python3 - "$embed_work" <<'PY'
|
||||
import pathlib
|
||||
import struct
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
work = pathlib.Path(sys.argv[1])
|
||||
project = work / 'project'
|
||||
wide = 'long' * 100
|
||||
body = f'''\n阅读正文含有公式 $r^2$ 与 [跳到详情](#detail)。
|
||||
|
||||
  
|
||||
|
||||
[远程链接](https://example.invalid) [缺失锚点](#missing) [其他文稿](other.mq.md)
|
||||
|
||||
<script>window.embeddedAttackDetected = true</script>
|
||||
|
||||
| 文字 | 列 |
|
||||
| --- | --- |
|
||||
| {wide} | 示例 |
|
||||
|
||||
```text
|
||||
{wide}
|
||||
```
|
||||
|
||||
## Detail
|
||||
|
||||
> 一段引用。
|
||||
'''
|
||||
(project / 'index.mq.md').write_text('# @knowledge 阅读\n' + body)
|
||||
(project / 'plain.md').write_text('# 阅读\n' + body)
|
||||
(project / 'other.mq.md').write_text('# @knowledge 不应打包\n')
|
||||
def chunk(name, data):
|
||||
return struct.pack('>I', len(data)) + name + data + struct.pack('>I', zlib.crc32(name + data))
|
||||
image = (b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', 1, 1, 8, 2, 0, 0, 0))
|
||||
+ chunk(b'IDAT', zlib.compress(b'\x00\xA0\x00\x50')) + chunk(b'IEND', b''))
|
||||
(project / 'image.png').write_bytes(image)
|
||||
(work / 'outside.png').write_bytes(image)
|
||||
(project / 'escape.png').symlink_to('../outside.png')
|
||||
PY
|
||||
for source in index.mq.md plain.md; do
|
||||
document="$embed_work/project/$source"
|
||||
document_sha="$(sha256sum "$document" | cut -d' ' -f1)"
|
||||
"${view[@]}" export "$document" --out "$embed_work/$source" --embed \
|
||||
--theme dark --anchor detail --expect-source-sha256 "$document_sha"
|
||||
done
|
||||
for option in --anchor --expect-source-sha256; do
|
||||
if "${view[@]}" export "$document" --out "$embed_work/invalid" --embed \
|
||||
"$option" missing > "$embed_work/rejection.log" 2>&1; then
|
||||
echo "error: embedded export accepted invalid $option" >&2
|
||||
exit 1
|
||||
fi
|
||||
rg -q 'view.export_(invalid|source_changed)' "$embed_work/rejection.log"
|
||||
test ! -e "$embed_work/invalid"
|
||||
done
|
||||
|
||||
# X-04: open the exported site from file:// in a real browser (offline).
|
||||
if [[ -d "$repo_root/tests/browser/node_modules/playwright" ]]; then
|
||||
PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-$repo_root/tests/.cache/pw-browsers}" \
|
||||
@@ -144,6 +204,8 @@ const { chromium } = require(path.join(process.argv[2], "node_modules/playwright
|
||||
await browser.close();
|
||||
})().catch((error) => { console.error(error.message); process.exit(1); });
|
||||
JS
|
||||
PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-$repo_root/tests/.cache/pw-browsers}" \
|
||||
node tests/browser/embedded.browser.cjs "$embed_work" "${view[@]}"
|
||||
else
|
||||
echo "note: Playwright not installed; skipped file:// browser check"
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user