Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcaa3b38a2 | ||
|
|
957edf9b0d | ||
|
|
250633fdca | ||
|
|
3c14251c28 | ||
|
|
b03e08ac20 | ||
|
|
86a2adc25b |
No files matched your search
@@ -1 +0,0 @@
|
|||||||
dist/
|
|
||||||
+1
-1
@@ -8,6 +8,6 @@ when:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
test:
|
test:
|
||||||
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.5
|
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.6
|
||||||
commands:
|
commands:
|
||||||
- sh scripts/test.sh
|
- sh scripts/test.sh
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Protected publish workflow: tag or manual only.
|
|
||||||
when:
|
|
||||||
- event: [tag, manual]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
publish:
|
|
||||||
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.5
|
|
||||||
environment:
|
|
||||||
GITEA_PUBLISH_TOKEN:
|
|
||||||
from_secret: gitea_publish_token
|
|
||||||
COMPONENT_ID: std-data
|
|
||||||
REPOSITORY: cflmy/marqdo-std-data
|
|
||||||
commands:
|
|
||||||
- |
|
|
||||||
set -eu
|
|
||||||
test -n "${GITEA_PUBLISH_TOKEN:?gitea_publish_token secret missing}"
|
|
||||||
test -n "${CI_COMMIT_TAG:?publish requires a tag}"
|
|
||||||
export SOURCE_SHA="${CI_COMMIT_SHA}"
|
|
||||||
export VERSION="${CI_COMMIT_TAG#v}"
|
|
||||||
export TAG="${CI_COMMIT_TAG}"
|
|
||||||
export COMPONENT_ID=std-data
|
|
||||||
export REPOSITORY=cflmy/marqdo-std-data
|
|
||||||
sh scripts/package.sh
|
|
||||||
ARCHIVE="dist/marqdo-std-data-${VERSION}-source.tar.gz"
|
|
||||||
python3 scripts/release/publish_gitea.py \
|
|
||||||
--repo "cflmy/marqdo-std-data" \
|
|
||||||
--tag "$TAG" \
|
|
||||||
--target "$SOURCE_SHA" \
|
|
||||||
--prerelease \
|
|
||||||
--body "Automated source release for std-data $TAG." \
|
|
||||||
--asset "$ARCHIVE" \
|
|
||||||
--asset "${ARCHIVE}.sha256" \
|
|
||||||
--asset dist/release-evidence.json \
|
|
||||||
--evidence-out dist/gitea-publish-result.json
|
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
# Fast-path notification after a completed Gitea release.
|
# Fast-path notification: a completed Gitea release asks the root reconcile
|
||||||
|
# workflow to check it. The payload is only a hint; the root reconcile verifies
|
||||||
|
# the release/assets from the authoritative Gitea API. A lost call is recovered
|
||||||
|
# by the root `release-reconcile` cron.
|
||||||
when:
|
when:
|
||||||
event: [release]
|
event: [release]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
notify:
|
notify:
|
||||||
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.5
|
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.6
|
||||||
environment:
|
environment:
|
||||||
WOODPECKER_NOTIFY_TOKEN:
|
WOODPECKER_TOKEN:
|
||||||
from_secret: woodpecker_notify_token
|
from_secret: woodpecker_token
|
||||||
commands:
|
commands:
|
||||||
- |
|
- |
|
||||||
set -eu
|
set -eu
|
||||||
test -n "${WOODPECKER_NOTIFY_TOKEN:?woodpecker_notify_token secret missing}"
|
test -n "${WOODPECKER_TOKEN:?woodpecker_token secret missing}"
|
||||||
python3 scripts/release/notify_root.py \
|
curl -fsS -X POST -H "Authorization: Bearer $WOODPECKER_TOKEN" -H "Content-Type: application/json" -d '{"branch":"main","workflow":"reconcile"}' https://ci.cflmy.cn/api/repos/6/pipelines
|
||||||
--hint-component "std-data" \
|
|
||||||
--hint-tag "${CI_COMMIT_TAG:-}"
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
| 发布路径 | 公开导入 | 职责 |
|
| 发布路径 | 公开导入 | 职责 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `data/json.mq.md` | `std:data/json` | 递归 JSON 解析/格式化(128 层上限、多值) |
|
| `data/json.mq.md` | `std:data/json` | 递归 JSON 解析/格式化(128 层上限、多值);显式严格入口 `json.严格解析` 拒绝同层重复键(按解码后键比较,含转义等价)与无法表示为有限值的数字(`json.duplicate_key` / `json.non_finite_number`),普通 `json.解析` 行为不变。 |
|
||||||
| `data/csv.mq.md` | `std:data/csv` | 引号单行/多行 CSV 解析与格式化 |
|
| `data/csv.mq.md` | `std:data/csv` | 引号单行/多行 CSV 解析与格式化 |
|
||||||
| `data/table.mq.md` | `std:data/table` | Table 序列化:`连接片段`、`连接行`、`转义单元格`、`转GFM` |
|
| `data/table.mq.md` | `std:data/table` | Table 序列化:`连接片段`、`连接行`、`转义单元格`、`转GFM` |
|
||||||
|
|
||||||
@@ -26,6 +26,12 @@
|
|||||||
MARQDO_BIN=/path/to/verified/marqdo \
|
MARQDO_BIN=/path/to/verified/marqdo \
|
||||||
MARQDO_STDLIB_DIR=/path/to/installed/bundle \
|
MARQDO_STDLIB_DIR=/path/to/installed/bundle \
|
||||||
scripts/test.sh
|
scripts/test.sh
|
||||||
|
|
||||||
|
# Candidate-input strict suite: requires a Bundle built from this component's
|
||||||
|
# current gitlink (the frozen ecosystem Bundle predates `json.严格解析`).
|
||||||
|
MARQDO_BIN=/path/to/verified/marqdo \
|
||||||
|
MARQDO_STDLIB_DIR=/path/to/candidate/bundle \
|
||||||
|
scripts/test-strict.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
期望值取自迁移前基线 Bundle 的真实执行(JSON/CSV 分项断言、Table GFM 输出);修改期望值等于声明公开行为变化,必须单独评审。
|
期望值取自迁移前基线 Bundle 的真实执行(JSON/CSV 分项断言、Table GFM 输出);修改期望值等于声明公开行为变化,必须单独评审。
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# std-data 严格 JSON 入口 — 2026-11-30
|
||||||
|
|
||||||
|
Issue: [marqdo-std-data#13](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/13)
|
||||||
|
(consumer: `marqdo-ext-ai` AI-U2b). Branch `codex/issue-13-strict-json`.
|
||||||
|
|
||||||
|
## 交付
|
||||||
|
|
||||||
|
* `data/json.mq.md` 新增显式严格入口 `json.严格解析(文本)`:
|
||||||
|
- 同一对象层重复键(按解码后键比较,`"a"` 与 `"\u0061"` 等价)→
|
||||||
|
`json.duplicate_key`;
|
||||||
|
- 无法表示为 binary64 有限值的数字(如 `1e400`、`-1e400`、`1.8e308`)→
|
||||||
|
`json.non_finite_number`;`1e308`、`1.79e308` 仍为有限值;
|
||||||
|
- 复用现有 tokenizer/解析器与 128 层深度上限,不新增第二套 JSON 语法。
|
||||||
|
* 普通 `json.解析` 公开行为不变(默认套件 PASS)。
|
||||||
|
* 候选输入自测:`tests/json-strict.mq.md` + `tests/cases-strict/json-strict.json`
|
||||||
|
+ `scripts/test-strict.sh`。严格入口只存在于本仓当前模块,冻结生态 Bundle
|
||||||
|
尚未含它,因此该套件与默认 `scripts/test.sh` 分离,由调用方显式传入候选
|
||||||
|
Bundle(根 Bundle 生产者/晋升流水线)。
|
||||||
|
* `scripts/run_cases.py` 支持 `MARQDO_STDLIB_CASES_DIR` 选择用例目录(默认不变)。
|
||||||
|
|
||||||
|
## 验证(真实执行)
|
||||||
|
|
||||||
|
环境:Linux x86_64 / glibc 2.43;CLI `marqdo 3.0.0-rc.6`(CLI candidate
|
||||||
|
`0f87f856…` 构建);本仓模块 `sha256:0f099d0279e0ea8c5d40b00ff3f2ff3ff8bccad551d61898f1c995e1d6a29407`。
|
||||||
|
|
||||||
|
候选 Bundle:pinned `marqdo-stdlib 0.2.0` 叠加本仓当前 `modules/` 后重算 tree
|
||||||
|
digest,得到 `sha256:4e47b0ff4b1e17d252cc74f20837014298fed4831050d65ca0c69f9cbdac55e9`
|
||||||
|
(17 个 `.mq.md`;仅本地候选,不是官方 manifest)。
|
||||||
|
|
||||||
|
```text
|
||||||
|
$ MARQDO_BIN=<rc.6> MARQDO_STDLIB_DIR=<candidate-bundle> sh scripts/test.sh
|
||||||
|
PASS csv
|
||||||
|
PASS json
|
||||||
|
PASS table
|
||||||
|
3 cases passed
|
||||||
|
|
||||||
|
$ MARQDO_BIN=<rc.6> MARQDO_STDLIB_DIR=<candidate-bundle> sh scripts/test-strict.sh
|
||||||
|
PASS json-strict
|
||||||
|
1 cases passed
|
||||||
|
```
|
||||||
|
|
||||||
|
严格入口行为(真实 CLI 运行,逐项断言在 `tests/cases-strict/json-strict.json`):
|
||||||
|
|
||||||
|
| 输入 | 结果 |
|
||||||
|
|---|---|
|
||||||
|
| `{"b":3,"c":[1,2.5,true,null]}` | ok |
|
||||||
|
| `[1,2.5,true,null,"x",{"b":3}]` | ok |
|
||||||
|
| `{"a":1,"a":2}` | `json.duplicate_key` |
|
||||||
|
| `{"a":1,"\u0061":2}` | `json.duplicate_key` |
|
||||||
|
| `1e400` / `-1e400` | `json.non_finite_number` |
|
||||||
|
| `1e308` / `1.79e308` | ok |
|
||||||
|
| `1.8e308` | `json.non_finite_number` |
|
||||||
|
| 普通 `json.解析("{\"a\":1,\"a\":2}")` | ok,`value={"a":2}`(行为不变) |
|
||||||
|
|
||||||
|
## 未验证 / 边界
|
||||||
|
|
||||||
|
* 冻结生态 Bundle 0.2.0 不含严格入口,仓库默认 CI 套件不覆盖新入口;候选
|
||||||
|
Bundle 由根生产者/晋升流水线提供,本仓不自建第二份官方 manifest。
|
||||||
|
* 未修改 CLI/其它组件;未新增跨仓依赖;未创建 release/tag。
|
||||||
|
* 转义等价按解码后键比较(`\u0061`);未额外做 Unicode 规范化,与普通键语义一致。
|
||||||
@@ -918,3 +918,386 @@ JSON 数字:可选负号、整数位、可选小数位、可选指数;含 ./
|
|||||||
|
|
||||||
`end`
|
`end`
|
||||||
`return {ok: true, value: 结果}`
|
`return {ok: true, value: 结果}`
|
||||||
|
|
||||||
|
## 严格解析
|
||||||
|
|
||||||
|
`params(文本)`
|
||||||
|
|
||||||
|
在普通解析之外显式选择严格语义:拒绝同一对象层内的重复键(按解码后
|
||||||
|
键比较)与无法表示为有限值的数字;普通 json.解析 的公开行为不变。
|
||||||
|
|
||||||
|
**点 = text.codepoints(文本)**
|
||||||
|
|
||||||
|
`if 嵌套深度(文本) > 128`
|
||||||
|
`return 失败("json.depth", "嵌套深度超过 128")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**检查 = 严格检查值(点, 0)**
|
||||||
|
|
||||||
|
`if not 检查.ok`
|
||||||
|
`return 检查`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 检查.next)**
|
||||||
|
|
||||||
|
`if 位置 != 长度(点)`
|
||||||
|
`return 失败("json.trailing", "值后存在多余输入")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
`return 解析(文本)`
|
||||||
|
|
||||||
|
## 严格检查值
|
||||||
|
|
||||||
|
`params(点, 位置)`
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 位置)**
|
||||||
|
|
||||||
|
`if 位置 >= 长度(点)`
|
||||||
|
`return 失败("json.unexpected_eof", "需要值")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**码点 = 点[位置]**
|
||||||
|
|
||||||
|
`if 码点 == 123`
|
||||||
|
`return 严格检查对象(点, 位置 + 1)`
|
||||||
|
`else`
|
||||||
|
`if 码点 == 91`
|
||||||
|
`return 严格检查数组(点, 位置 + 1)`
|
||||||
|
`else`
|
||||||
|
`if 码点 == 34`
|
||||||
|
**文本结果 = 解析字符串(点, 位置)**
|
||||||
|
`if not 文本结果.ok`
|
||||||
|
`return 文本结果`
|
||||||
|
`end`
|
||||||
|
`return 成功值(None, 文本结果.next)`
|
||||||
|
`else`
|
||||||
|
`if 码点 == 45 or 是数字(码点)`
|
||||||
|
**开始 = 位置**
|
||||||
|
**数字结果 = 解析数字(点, 位置)**
|
||||||
|
`if not 数字结果.ok`
|
||||||
|
`return 数字结果`
|
||||||
|
`end`
|
||||||
|
**原文 = 片段(点, 开始, 数字结果.next)**
|
||||||
|
`if not 有限数字文本(原文)`
|
||||||
|
`return 失败("json.non_finite_number", "数字无法表示为有限值")`
|
||||||
|
`end`
|
||||||
|
`return 成功值(None, 数字结果.next)`
|
||||||
|
`else`
|
||||||
|
`return 解析值(点, 位置)`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
## 严格检查对象
|
||||||
|
|
||||||
|
`params(点, 位置)`
|
||||||
|
`return 严格检查对象项(点, 位置, {})`
|
||||||
|
|
||||||
|
## 严格检查对象项
|
||||||
|
|
||||||
|
`params(点, 位置, 已见)`
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 位置)**
|
||||||
|
|
||||||
|
`if 位置 >= 长度(点)`
|
||||||
|
`return 失败("json.unexpected_eof", "对象未闭合")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**当前 = text.from_codepoint(点[位置])**
|
||||||
|
|
||||||
|
`if 当前 == "}"`
|
||||||
|
`return 成功值(None, 位置 + 1)`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**键结果 = 解析字符串(点, 位置)**
|
||||||
|
|
||||||
|
`if not 键结果.ok`
|
||||||
|
`return 键结果`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**键 = 键结果.value**
|
||||||
|
|
||||||
|
`if map.has(已见, 键)`
|
||||||
|
`return 失败("json.duplicate_key", "同一对象层内存在重复键")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**更新的已见 = map.set(已见, 键, true)**
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 键结果.next)**
|
||||||
|
|
||||||
|
`if 位置 >= 长度(点)`
|
||||||
|
`return 失败("json.unexpected_eof", "对象缺少冒号")`
|
||||||
|
`else`
|
||||||
|
`if text.from_codepoint(点[位置]) != ":"`
|
||||||
|
`return 失败("json.invalid_object", "对象缺少冒号")`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**值检查 = 严格检查值(点, 位置 + 1)**
|
||||||
|
|
||||||
|
`if not 值检查.ok`
|
||||||
|
`return 值检查`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 值检查.next)**
|
||||||
|
|
||||||
|
`if 位置 >= 长度(点)`
|
||||||
|
`return 失败("json.unexpected_eof", "对象未闭合")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**分隔 = text.from_codepoint(点[位置])**
|
||||||
|
|
||||||
|
`if 分隔 == ","`
|
||||||
|
`return 严格检查对象项(点, 位置 + 1, 更新的已见)`
|
||||||
|
`else`
|
||||||
|
`if 分隔 == "}"`
|
||||||
|
`return 成功值(None, 位置 + 1)`
|
||||||
|
`else`
|
||||||
|
`return 失败("json.invalid_object", "对象缺少逗号或 }")`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
## 严格检查数组
|
||||||
|
|
||||||
|
`params(点, 位置)`
|
||||||
|
`return 严格检查数组项(点, 位置)`
|
||||||
|
|
||||||
|
## 严格检查数组项
|
||||||
|
|
||||||
|
`params(点, 位置)`
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 位置)**
|
||||||
|
|
||||||
|
`if 位置 >= 长度(点)`
|
||||||
|
`return 失败("json.unexpected_eof", "数组未闭合")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**当前 = text.from_codepoint(点[位置])**
|
||||||
|
|
||||||
|
`if 当前 == "]"`
|
||||||
|
`return 成功值(None, 位置 + 1)`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**项检查 = 严格检查值(点, 位置)**
|
||||||
|
|
||||||
|
`if not 项检查.ok`
|
||||||
|
`return 项检查`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**位置 = 跳过空白(点, 项检查.next)**
|
||||||
|
|
||||||
|
`if 位置 >= 长度(点)`
|
||||||
|
`return 失败("json.unexpected_eof", "数组未闭合")`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**分隔 = text.from_codepoint(点[位置])**
|
||||||
|
|
||||||
|
`if 分隔 == ","`
|
||||||
|
`return 严格检查数组项(点, 位置 + 1)`
|
||||||
|
`else`
|
||||||
|
`if 分隔 == "]"`
|
||||||
|
`return 成功值(None, 位置 + 1)`
|
||||||
|
`else`
|
||||||
|
`return 失败("json.invalid_array", "数组缺少逗号或 ]")`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
## 有限数字文本
|
||||||
|
|
||||||
|
`params(原文)`
|
||||||
|
|
||||||
|
判断 JSON 数字原文是否可用 binary64 有限值表示:十进制量级超过 308
|
||||||
|
即溢出;量级正好 308 时与 binary64 最大值 1.7976931348623157e308 的
|
||||||
|
显著数字比较。下溢为 0 仍属有限值。
|
||||||
|
|
||||||
|
**点 = text.codepoints(原文)**
|
||||||
|
|
||||||
|
**下标 = 0**
|
||||||
|
|
||||||
|
`if 下标 < 长度(点) and 点[下标] == 45`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**忽略符号 = 0**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**整数起 = 下标**
|
||||||
|
|
||||||
|
`while 下标 < 长度(点) and 是数字(点[下标])`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**整数终 = 下标**
|
||||||
|
|
||||||
|
**小数起 = 下标**
|
||||||
|
|
||||||
|
`if 下标 < 长度(点) and 点[下标] == 46`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
**小数起 = 下标**
|
||||||
|
`while 下标 < 长度(点) and 是数字(点[下标])`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**忽略小数 = 0**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**小数终 = 下标**
|
||||||
|
|
||||||
|
**指数 = 0**
|
||||||
|
|
||||||
|
`if 下标 < 长度(点) and (点[下标] == 101 or 点[下标] == 69)`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
**指数负 = false**
|
||||||
|
`if 下标 < 长度(点) and 点[下标] == 43`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`else`
|
||||||
|
`if 下标 < 长度(点) and 点[下标] == 45`
|
||||||
|
**指数负 = true**
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**忽略指数符号 = 0**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
`while 下标 < 长度(点) and 是数字(点[下标])`
|
||||||
|
`if 指数 < 100000`
|
||||||
|
**指数 = 指数 * 10 + (点[下标] - 48)**
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**指数 = 100000**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
`if 指数负`
|
||||||
|
**指数 = 0 - 指数**
|
||||||
|
`end`
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**忽略指数 = 0**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**有效 = 严格有效数字(点, 整数起, 整数终, 小数起, 小数终)**
|
||||||
|
|
||||||
|
`if 长度(有效) == 0`
|
||||||
|
`return true`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**量级 = 0**
|
||||||
|
|
||||||
|
`if 有效首位整数(点, 整数起, 整数终)`
|
||||||
|
**量级 = (整数终 - 有效起点(点, 整数起, 整数终)) - 1 + 指数**
|
||||||
|
`else`
|
||||||
|
**量级 = (0 - (有效起点(点, 小数起, 小数终) - 小数起 + 1)) + 指数**
|
||||||
|
`end`
|
||||||
|
|
||||||
|
`if 量级 > 308`
|
||||||
|
`return false`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
`if 量级 < 308`
|
||||||
|
`return true`
|
||||||
|
`end`
|
||||||
|
|
||||||
|
`return 有效数字不超过上限(有效)`
|
||||||
|
|
||||||
|
## 有效首位整数
|
||||||
|
|
||||||
|
`params(点, 起点, 终点)`
|
||||||
|
|
||||||
|
**下标 = 起点**
|
||||||
|
|
||||||
|
`while 下标 < 终点`
|
||||||
|
`if 点[下标] != 48`
|
||||||
|
`return true`
|
||||||
|
`end`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
`return false`
|
||||||
|
|
||||||
|
## 有效起点
|
||||||
|
|
||||||
|
`params(点, 起点, 终点)`
|
||||||
|
|
||||||
|
**下标 = 起点**
|
||||||
|
|
||||||
|
`while 下标 < 终点`
|
||||||
|
`if 点[下标] != 48`
|
||||||
|
`return 下标`
|
||||||
|
`end`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
`return 终点`
|
||||||
|
|
||||||
|
## 严格有效数字
|
||||||
|
|
||||||
|
`params(点, 整数起, 整数终, 小数起, 小数终)`
|
||||||
|
|
||||||
|
**有效 = []**
|
||||||
|
|
||||||
|
**开始 = false**
|
||||||
|
|
||||||
|
**下标 = 整数起**
|
||||||
|
|
||||||
|
`while 下标 < 整数终`
|
||||||
|
`if 开始 or 点[下标] != 48`
|
||||||
|
**开始 = true**
|
||||||
|
`if 长度(有效) < 17`
|
||||||
|
**有效 = list.append(有效, 点[下标] - 48)**
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**忽略多余 = 0**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
|
||||||
|
**下标 = 小数起**
|
||||||
|
|
||||||
|
`while 下标 < 小数终`
|
||||||
|
`if 开始 or 点[下标] != 48`
|
||||||
|
**开始 = true**
|
||||||
|
`if 长度(有效) < 17`
|
||||||
|
**有效 = list.append(有效, 点[下标] - 48)**
|
||||||
|
`else`
|
||||||
|
`if true`
|
||||||
|
**忽略多余 = 0**
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
`end`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
|
||||||
|
`return 有效`
|
||||||
|
|
||||||
|
## 有效数字不超过上限
|
||||||
|
|
||||||
|
`params(有效)`
|
||||||
|
|
||||||
|
**上限 = text.codepoints("17976931348623157")**
|
||||||
|
|
||||||
|
**下标 = 0**
|
||||||
|
|
||||||
|
`while 下标 < 17`
|
||||||
|
**数字 = 0**
|
||||||
|
`if 下标 < 长度(有效)`
|
||||||
|
**数字 = 有效[下标]**
|
||||||
|
`end`
|
||||||
|
**限制 = 上限[下标] - 48**
|
||||||
|
`if 数字 > 限制`
|
||||||
|
`return false`
|
||||||
|
`end`
|
||||||
|
`if 数字 < 限制`
|
||||||
|
`return true`
|
||||||
|
`end`
|
||||||
|
**下标 = 下标 + 1**
|
||||||
|
`end`
|
||||||
|
|
||||||
|
`return true`
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Deterministic source archive + release-evidence.json for this component.
|
|
||||||
#
|
|
||||||
# Required env:
|
|
||||||
# COMPONENT_ID catalog id (e.g. std-text)
|
|
||||||
# REPOSITORY owner/name (e.g. cflmy/marqdo-std-text)
|
|
||||||
# Optional:
|
|
||||||
# VERSION without leading v (default: derived from CI_COMMIT_TAG)
|
|
||||||
# SOURCE_SHA full commit (default: HEAD)
|
|
||||||
# OUT_DIR default dist
|
|
||||||
# DEPENDENCY repeatable write_evidence dependency specs via env DEP_ARGS
|
|
||||||
set -eu
|
|
||||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
||||||
COMPONENT_ID=${COMPONENT_ID:?COMPONENT_ID is required}
|
|
||||||
REPOSITORY=${REPOSITORY:?REPOSITORY is required}
|
|
||||||
SOURCE_SHA=${SOURCE_SHA:-$(git -C "$ROOT" rev-parse HEAD)}
|
|
||||||
OUT_DIR=${OUT_DIR:-dist}
|
|
||||||
TAG=${CI_COMMIT_TAG:-${TAG:-}}
|
|
||||||
if [ -n "${VERSION:-}" ]; then
|
|
||||||
:
|
|
||||||
elif [ -n "$TAG" ]; then
|
|
||||||
VERSION=${TAG#v}
|
|
||||||
else
|
|
||||||
echo "package.sh: set VERSION or CI_COMMIT_TAG" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
TAG=${TAG:-v$VERSION}
|
|
||||||
|
|
||||||
python3 "$ROOT/scripts/release/package_source.py" \
|
|
||||||
--root "$ROOT" \
|
|
||||||
--component-id "$COMPONENT_ID" \
|
|
||||||
--version "$VERSION" \
|
|
||||||
--out-dir "$OUT_DIR"
|
|
||||||
|
|
||||||
ARCHIVE=$(ls "$ROOT/$OUT_DIR"/marqdo-"$COMPONENT_ID"-"$VERSION"-source.tar.gz)
|
|
||||||
SHAFILE="$ARCHIVE.sha256"
|
|
||||||
|
|
||||||
EVIDENCE_ARGS="--component-id $COMPONENT_ID --repository $REPOSITORY --tag $TAG --source-sha $SOURCE_SHA --asset $ARCHIVE --asset $SHAFILE --out $ROOT/$OUT_DIR/release-evidence.json"
|
|
||||||
if [ -n "${CI_PIPELINE_NUMBER:-}" ]; then
|
|
||||||
EVIDENCE_ARGS="$EVIDENCE_ARGS --pipeline-number $CI_PIPELINE_NUMBER"
|
|
||||||
fi
|
|
||||||
if [ -n "${CI_PIPELINE_URL:-}" ]; then
|
|
||||||
EVIDENCE_ARGS="$EVIDENCE_ARGS --pipeline-url $CI_PIPELINE_URL"
|
|
||||||
fi
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
eval "python3 \"$ROOT/scripts/release/write_evidence.py\" $EVIDENCE_ARGS ${DEP_ARGS:-}"
|
|
||||||
echo "$ARCHIVE"
|
|
||||||
echo "$SHAFILE"
|
|
||||||
echo "$ROOT/$OUT_DIR/release-evidence.json"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# Vendored from marqdo scripts/component-release
|
|
||||||
#
|
|
||||||
# Do not edit in place across repositories. Change the root copy, re-test,
|
|
||||||
# then re-run install-vendor.sh and record the hashes below.
|
|
||||||
#
|
|
||||||
# package_source.py sha256=cb18c2f7fbe807f55d49e2cf77720f0d3e57d355177d2b127ac09e119f90c6ae
|
|
||||||
# write_evidence.py sha256=bb194bfd251e39308bc1dd53f46fd9efac181082ea43f668484b067d9e54acfc
|
|
||||||
# publish_gitea.py sha256=a21a84146d9ea826eb8d0632a18a991b0c39f17005d83bd988c92fc608f67523
|
|
||||||
# notify_root.py sha256=8eee83eb2bb31b99d93981f2a97fc2f0f9a486cc3c5c072f7dc12cfb63baf025
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Ask the root Marqdo reconcile workflow to scan after a release.
|
|
||||||
|
|
||||||
The payload is only a hint. Correctness comes from the root
|
|
||||||
`scripts/reconcile-releases.py` reading authoritative Gitea releases.
|
|
||||||
Lost notifications are recovered by the root `release-reconcile` cron.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import urllib.error
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
DEFAULT_URL = "https://ci.cflmy.cn/api/repos/6/pipelines"
|
|
||||||
DEFAULT_BODY = {"branch": "main", "workflow": "reconcile"}
|
|
||||||
|
|
||||||
|
|
||||||
class NotifyError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def token() -> str:
|
|
||||||
value = (
|
|
||||||
os.environ.get("WOODPECKER_NOTIFY_TOKEN")
|
|
||||||
or os.environ.get("WOODPECKER_TOKEN")
|
|
||||||
or os.environ.get("woodpecker_token")
|
|
||||||
)
|
|
||||||
if not value:
|
|
||||||
raise NotifyError("WOODPECKER_NOTIFY_TOKEN (or WOODPECKER_TOKEN) is not set")
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
def trigger(url: str, token_value: str, body: dict, attempts: int = 3) -> dict:
|
|
||||||
payload = json.dumps(body).encode()
|
|
||||||
last_error: Exception | None = None
|
|
||||||
for attempt in range(1, attempts + 1):
|
|
||||||
request = urllib.request.Request(
|
|
||||||
url,
|
|
||||||
data=payload,
|
|
||||||
method="POST",
|
|
||||||
headers={
|
|
||||||
"Authorization": f"Bearer {token_value}",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(request, timeout=60) as response:
|
|
||||||
raw = response.read()
|
|
||||||
decoded = json.loads(raw) if raw else {}
|
|
||||||
return {
|
|
||||||
"status": "triggered",
|
|
||||||
"http_status": response.status,
|
|
||||||
"pipeline_id": decoded.get("id"),
|
|
||||||
"pipeline_number": decoded.get("number"),
|
|
||||||
"attempt": attempt,
|
|
||||||
}
|
|
||||||
except urllib.error.HTTPError as error:
|
|
||||||
# Auth/permission failures must not retry forever.
|
|
||||||
if error.code in (401, 403, 404):
|
|
||||||
raise NotifyError(f"trigger rejected with HTTP {error.code}") from error
|
|
||||||
last_error = error
|
|
||||||
except urllib.error.URLError as error:
|
|
||||||
last_error = error
|
|
||||||
if attempt < attempts:
|
|
||||||
delay = (2 ** (attempt - 1)) + random.uniform(0, 0.5)
|
|
||||||
time.sleep(delay)
|
|
||||||
raise NotifyError(f"trigger failed after {attempts} attempts: {last_error}")
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv: list[str] | None = None) -> int:
|
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
|
||||||
parser.add_argument("--url", default=os.environ.get("MARQDO_RECONCILE_TRIGGER_URL", DEFAULT_URL))
|
|
||||||
parser.add_argument("--branch", default="main")
|
|
||||||
parser.add_argument("--workflow", default="reconcile")
|
|
||||||
parser.add_argument("--hint-component", default="")
|
|
||||||
parser.add_argument("--hint-tag", default="")
|
|
||||||
parser.add_argument("--attempts", type=int, default=3)
|
|
||||||
args = parser.parse_args(argv)
|
|
||||||
body = {"branch": args.branch, "workflow": args.workflow}
|
|
||||||
# Hints are informational only; the root reconcile never trusts them as commands.
|
|
||||||
if args.hint_component or args.hint_tag:
|
|
||||||
body["variables"] = {
|
|
||||||
"MARQDO_RELEASE_HINT_COMPONENT": args.hint_component,
|
|
||||||
"MARQDO_RELEASE_HINT_TAG": args.hint_tag,
|
|
||||||
}
|
|
||||||
try:
|
|
||||||
result = trigger(args.url, token(), body, attempts=max(1, args.attempts))
|
|
||||||
except NotifyError as error:
|
|
||||||
print(f"notify_root: FAIL: {error}", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
print(json.dumps(result, indent=2, sort_keys=True))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
raise SystemExit(main())
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Build a deterministic source archive for a Marqdo component release.
|
|
||||||
|
|
||||||
Only allowlisted relative paths are included. The archive uses fixed mtime,
|
|
||||||
uid/gid, and sorted member names so the same tree always yields the same
|
|
||||||
sha256. Output is written under an isolated directory (default: dist/).
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import hashlib
|
|
||||||
import io
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import tarfile
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
DEFAULT_ALLOWLIST = (
|
|
||||||
"modules",
|
|
||||||
"index.mq.md",
|
|
||||||
"marqdo.yaml",
|
|
||||||
"LICENSE",
|
|
||||||
"README.md",
|
|
||||||
)
|
|
||||||
FIXED_MTIME = 0
|
|
||||||
EVIDENCE_NAME = "release-evidence.json"
|
|
||||||
|
|
||||||
|
|
||||||
class PackageError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def fail(message: str) -> None:
|
|
||||||
raise PackageError(message)
|
|
||||||
|
|
||||||
|
|
||||||
def is_safe_relative(path: str) -> bool:
|
|
||||||
if not path or path.startswith("/") or path.startswith("\\"):
|
|
||||||
return False
|
|
||||||
parts = Path(path).parts
|
|
||||||
return not any(part in (".", "..") for part in parts)
|
|
||||||
|
|
||||||
|
|
||||||
def collect_files(root: Path, allowlist: list[str]) -> list[tuple[str, Path]]:
|
|
||||||
selected: dict[str, Path] = {}
|
|
||||||
for entry in allowlist:
|
|
||||||
if not is_safe_relative(entry):
|
|
||||||
fail(f"unsafe allowlist entry: {entry!r}")
|
|
||||||
target = root / entry
|
|
||||||
if not target.exists():
|
|
||||||
continue
|
|
||||||
if target.is_file():
|
|
||||||
selected[entry.replace("\\", "/")] = target
|
|
||||||
continue
|
|
||||||
if not target.is_dir():
|
|
||||||
fail(f"allowlist entry is not a regular file or directory: {entry}")
|
|
||||||
for path in sorted(target.rglob("*")):
|
|
||||||
if not path.is_file():
|
|
||||||
continue
|
|
||||||
if path.is_symlink():
|
|
||||||
fail(f"symlinks are not publishable: {path.relative_to(root)}")
|
|
||||||
relative = path.relative_to(root).as_posix()
|
|
||||||
if not is_safe_relative(relative):
|
|
||||||
fail(f"unsafe relative path: {relative}")
|
|
||||||
selected[relative] = path
|
|
||||||
if not selected:
|
|
||||||
fail("allowlist matched no files")
|
|
||||||
return sorted(selected.items(), key=lambda item: item[0])
|
|
||||||
|
|
||||||
|
|
||||||
def archive_bytes(files: list[tuple[str, Path]]) -> bytes:
|
|
||||||
buffer = io.BytesIO()
|
|
||||||
with tarfile.open(fileobj=buffer, mode="w:gz", format=tarfile.PAX_FORMAT, compresslevel=9) as archive:
|
|
||||||
for relative, path in files:
|
|
||||||
data = path.read_bytes()
|
|
||||||
info = tarfile.TarInfo(name=relative)
|
|
||||||
info.size = len(data)
|
|
||||||
info.mtime = FIXED_MTIME
|
|
||||||
info.uid = 0
|
|
||||||
info.gid = 0
|
|
||||||
info.uname = ""
|
|
||||||
info.gname = ""
|
|
||||||
info.mode = 0o644
|
|
||||||
archive.addfile(info, io.BytesIO(data))
|
|
||||||
return buffer.getvalue()
|
|
||||||
|
|
||||||
|
|
||||||
def write_outputs(
|
|
||||||
root: Path,
|
|
||||||
out_dir: Path,
|
|
||||||
component_id: str,
|
|
||||||
version: str,
|
|
||||||
allowlist: list[str],
|
|
||||||
) -> dict:
|
|
||||||
files = collect_files(root, allowlist)
|
|
||||||
payload = archive_bytes(files)
|
|
||||||
digest = hashlib.sha256(payload).hexdigest()
|
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
archive_name = f"marqdo-{component_id}-{version}-source.tar.gz"
|
|
||||||
archive_path = out_dir / archive_name
|
|
||||||
sha_path = out_dir / f"{archive_name}.sha256"
|
|
||||||
archive_path.write_bytes(payload)
|
|
||||||
sha_path.write_text(f"{digest} {archive_name}\n", encoding="utf-8")
|
|
||||||
return {
|
|
||||||
"archive": str(archive_path),
|
|
||||||
"sha256_file": str(sha_path),
|
|
||||||
"name": archive_name,
|
|
||||||
"size": len(payload),
|
|
||||||
"sha256": digest,
|
|
||||||
"files": [relative for relative, _ in files],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv: list[str] | None = None) -> int:
|
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
|
||||||
parser.add_argument("--root", default=".", help="component repository root")
|
|
||||||
parser.add_argument("--component-id", required=True)
|
|
||||||
parser.add_argument("--version", required=True, help="version without leading v")
|
|
||||||
parser.add_argument("--out-dir", default="dist")
|
|
||||||
parser.add_argument(
|
|
||||||
"--allow",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="relative allowlist entry (repeatable); defaults applied when omitted",
|
|
||||||
)
|
|
||||||
args = parser.parse_args(argv)
|
|
||||||
allowlist = args.allow or list(DEFAULT_ALLOWLIST)
|
|
||||||
root = Path(args.root).resolve()
|
|
||||||
out_dir = Path(args.out_dir)
|
|
||||||
if not out_dir.is_absolute():
|
|
||||||
out_dir = root / out_dir
|
|
||||||
try:
|
|
||||||
result = write_outputs(root, out_dir, args.component_id, args.version, allowlist)
|
|
||||||
except PackageError as error:
|
|
||||||
print(f"package_source: FAIL: {error}", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
print(result["archive"])
|
|
||||||
print(result["sha256_file"])
|
|
||||||
print(f"sha256={result['sha256']} size={result['size']} files={len(result['files'])}")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
raise SystemExit(main())
|
|
||||||
@@ -1,352 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Publish a Gitea release with a draft transaction and immutable public assets.
|
|
||||||
|
|
||||||
Order (issue #10 §4.2):
|
|
||||||
create/reuse draft → upload non-index assets → upload release-evidence.json last
|
|
||||||
→ re-read and verify → mark non-draft → re-confirm.
|
|
||||||
|
|
||||||
Never deletes or replaces assets on an already-published (non-draft) release.
|
|
||||||
Identical published identity is treated as idempotent success.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import mimetypes
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import urllib.error
|
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
import uuid
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
DEFAULT_API = "https://git.cflmy.cn/api/v1"
|
|
||||||
INDEX_NAME = "release-evidence.json"
|
|
||||||
|
|
||||||
|
|
||||||
class PublishError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def token() -> str:
|
|
||||||
value = (
|
|
||||||
os.environ.get("GITEA_PUBLISH_TOKEN")
|
|
||||||
or os.environ.get("GITEA_TOKEN")
|
|
||||||
or os.environ.get("gitea_token")
|
|
||||||
)
|
|
||||||
if not value:
|
|
||||||
raise PublishError("GITEA_PUBLISH_TOKEN (or GITEA_TOKEN) is not set")
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
def request(
|
|
||||||
api: str,
|
|
||||||
method: str,
|
|
||||||
path: str,
|
|
||||||
token_value: str,
|
|
||||||
payload: dict | None = None,
|
|
||||||
raw: bytes | None = None,
|
|
||||||
content_type: str = "application/json",
|
|
||||||
) -> tuple[int, bytes]:
|
|
||||||
url = f"{api}{path}"
|
|
||||||
headers = {"Authorization": f"token {token_value}", "Accept": "application/json"}
|
|
||||||
data = None
|
|
||||||
if payload is not None:
|
|
||||||
data = json.dumps(payload).encode()
|
|
||||||
headers["Content-Type"] = content_type
|
|
||||||
elif raw is not None:
|
|
||||||
data = raw
|
|
||||||
headers["Content-Type"] = content_type
|
|
||||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req, timeout=120) as response:
|
|
||||||
return response.status, response.read()
|
|
||||||
except urllib.error.HTTPError as error:
|
|
||||||
return error.code, error.read()
|
|
||||||
|
|
||||||
|
|
||||||
def decode(body: bytes) -> object:
|
|
||||||
if not body:
|
|
||||||
return None
|
|
||||||
try:
|
|
||||||
return json.loads(body)
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def sha256_file(path: Path) -> str:
|
|
||||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
def get_release_by_tag(api: str, repo: str, tag: str, token_value: str) -> dict | None:
|
|
||||||
status, body = request(
|
|
||||||
api,
|
|
||||||
"GET",
|
|
||||||
f"/repos/{repo}/releases/tags/{urllib.parse.quote(tag, safe='')}",
|
|
||||||
token_value,
|
|
||||||
)
|
|
||||||
if status == 404:
|
|
||||||
return None
|
|
||||||
if status != 200:
|
|
||||||
raise PublishError(f"lookup release {tag} failed with HTTP {status}")
|
|
||||||
release = decode(body)
|
|
||||||
if not isinstance(release, dict) or "id" not in release:
|
|
||||||
raise PublishError("release lookup response malformed")
|
|
||||||
return release
|
|
||||||
|
|
||||||
|
|
||||||
def create_draft(
|
|
||||||
api: str,
|
|
||||||
repo: str,
|
|
||||||
tag: str,
|
|
||||||
body: str,
|
|
||||||
token_value: str,
|
|
||||||
*,
|
|
||||||
prerelease: bool,
|
|
||||||
target: str,
|
|
||||||
) -> dict:
|
|
||||||
payload = {
|
|
||||||
"tag_name": tag,
|
|
||||||
"name": tag,
|
|
||||||
"body": body,
|
|
||||||
"draft": True,
|
|
||||||
"prerelease": prerelease,
|
|
||||||
"target_commitish": target,
|
|
||||||
}
|
|
||||||
status, response = request(api, "POST", f"/repos/{repo}/releases", token_value, payload)
|
|
||||||
if status not in (200, 201):
|
|
||||||
raise PublishError(f"creating draft release failed with HTTP {status}: {response[:200]!r}")
|
|
||||||
release = decode(response)
|
|
||||||
if not isinstance(release, dict) or "id" not in release:
|
|
||||||
raise PublishError("draft create response malformed")
|
|
||||||
return release
|
|
||||||
|
|
||||||
|
|
||||||
def patch_release(api: str, repo: str, release_id: int, token_value: str, payload: dict) -> dict:
|
|
||||||
status, response = request(
|
|
||||||
api, "PATCH", f"/repos/{repo}/releases/{release_id}", token_value, payload
|
|
||||||
)
|
|
||||||
if status != 200:
|
|
||||||
raise PublishError(f"updating release {release_id} failed with HTTP {status}")
|
|
||||||
release = decode(response)
|
|
||||||
if not isinstance(release, dict):
|
|
||||||
raise PublishError("release patch response malformed")
|
|
||||||
return release
|
|
||||||
|
|
||||||
|
|
||||||
def list_assets(api: str, repo: str, release_id: int, token_value: str) -> list[dict]:
|
|
||||||
status, response = request(
|
|
||||||
api, "GET", f"/repos/{repo}/releases/{release_id}/assets", token_value
|
|
||||||
)
|
|
||||||
if status != 200:
|
|
||||||
raise PublishError(f"listing assets failed with HTTP {status}")
|
|
||||||
assets = decode(response)
|
|
||||||
if not isinstance(assets, list):
|
|
||||||
raise PublishError("asset list malformed")
|
|
||||||
return assets
|
|
||||||
|
|
||||||
|
|
||||||
def upload_asset(
|
|
||||||
api: str, repo: str, release_id: int, path: Path, token_value: str
|
|
||||||
) -> dict:
|
|
||||||
name = path.name
|
|
||||||
if not name or "/" in name or name in (".", ".."):
|
|
||||||
raise PublishError(f"unsafe asset name: {name!r}")
|
|
||||||
existing = list_assets(api, repo, release_id, token_value)
|
|
||||||
for asset in existing:
|
|
||||||
if asset.get("name") == name:
|
|
||||||
raise PublishError(
|
|
||||||
f"asset {name} already exists on draft/release {release_id}; "
|
|
||||||
"refusing to overwrite"
|
|
||||||
)
|
|
||||||
boundary = f"----marqdo{uuid.uuid4().hex}"
|
|
||||||
content_type = mimetypes.guess_type(name)[0] or "application/octet-stream"
|
|
||||||
body = bytearray()
|
|
||||||
body.extend(f"--{boundary}\r\n".encode())
|
|
||||||
body.extend(
|
|
||||||
f'Content-Disposition: form-data; name="attachment"; filename="{name}"\r\n'.encode()
|
|
||||||
)
|
|
||||||
body.extend(f"Content-Type: {content_type}\r\n\r\n".encode())
|
|
||||||
body.extend(path.read_bytes())
|
|
||||||
body.extend(f"\r\n--{boundary}--\r\n".encode())
|
|
||||||
status, response = request(
|
|
||||||
api,
|
|
||||||
"POST",
|
|
||||||
f"/repos/{repo}/releases/{release_id}/assets?name={urllib.parse.quote(name)}",
|
|
||||||
token_value,
|
|
||||||
raw=bytes(body),
|
|
||||||
content_type=f"multipart/form-data; boundary={boundary}",
|
|
||||||
)
|
|
||||||
if status not in (200, 201):
|
|
||||||
raise PublishError(f"uploading {name} failed with HTTP {status}: {response[:200]!r}")
|
|
||||||
result = decode(response)
|
|
||||||
if not isinstance(result, dict):
|
|
||||||
raise PublishError(f"upload response for {name} malformed")
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def asset_identity(path: Path) -> dict:
|
|
||||||
return {
|
|
||||||
"name": path.name,
|
|
||||||
"size": path.stat().st_size,
|
|
||||||
"sha256": sha256_file(path),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def published_matches(release: dict, expected: list[dict]) -> bool:
|
|
||||||
remote = {
|
|
||||||
asset.get("name"): int(asset.get("size") or -1)
|
|
||||||
for asset in (release.get("assets") or [])
|
|
||||||
}
|
|
||||||
if set(remote) != {item["name"] for item in expected}:
|
|
||||||
return False
|
|
||||||
for item in expected:
|
|
||||||
if remote.get(item["name"]) != item["size"]:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def publish(
|
|
||||||
*,
|
|
||||||
api: str,
|
|
||||||
repo: str,
|
|
||||||
tag: str,
|
|
||||||
body: str,
|
|
||||||
target: str,
|
|
||||||
assets: list[Path],
|
|
||||||
prerelease: bool,
|
|
||||||
token_value: str,
|
|
||||||
) -> dict:
|
|
||||||
if not assets:
|
|
||||||
raise PublishError("no assets to publish")
|
|
||||||
index_assets = [path for path in assets if path.name == INDEX_NAME]
|
|
||||||
other_assets = [path for path in assets if path.name != INDEX_NAME]
|
|
||||||
if len(index_assets) != 1:
|
|
||||||
raise PublishError("exactly one release-evidence.json is required")
|
|
||||||
ordered = other_assets + index_assets
|
|
||||||
expected = [asset_identity(path) for path in ordered]
|
|
||||||
|
|
||||||
existing = get_release_by_tag(api, repo, tag, token_value)
|
|
||||||
if existing and not existing.get("draft"):
|
|
||||||
if published_matches(existing, expected):
|
|
||||||
return {
|
|
||||||
"status": "idempotent",
|
|
||||||
"release_id": existing["id"],
|
|
||||||
"html_url": existing.get("html_url"),
|
|
||||||
"tag": tag,
|
|
||||||
"assets": expected,
|
|
||||||
}
|
|
||||||
raise PublishError(
|
|
||||||
f"published release {tag} already exists with different assets; "
|
|
||||||
"refusing to overwrite"
|
|
||||||
)
|
|
||||||
|
|
||||||
if existing and existing.get("draft"):
|
|
||||||
release = existing
|
|
||||||
# Keep draft body/target aligned when continuing an interrupted publish.
|
|
||||||
release = patch_release(
|
|
||||||
api,
|
|
||||||
repo,
|
|
||||||
int(release["id"]),
|
|
||||||
token_value,
|
|
||||||
{
|
|
||||||
"name": tag,
|
|
||||||
"body": body,
|
|
||||||
"draft": True,
|
|
||||||
"prerelease": prerelease,
|
|
||||||
"target_commitish": target,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
release = create_draft(
|
|
||||||
api, repo, tag, body, token_value, prerelease=prerelease, target=target
|
|
||||||
)
|
|
||||||
|
|
||||||
release_id = int(release["id"])
|
|
||||||
remote_names = {asset.get("name") for asset in list_assets(api, repo, release_id, token_value)}
|
|
||||||
for path in ordered:
|
|
||||||
if path.name in remote_names:
|
|
||||||
# Same-name asset already on this draft: require identical size, else fail.
|
|
||||||
match = next(
|
|
||||||
asset
|
|
||||||
for asset in list_assets(api, repo, release_id, token_value)
|
|
||||||
if asset.get("name") == path.name
|
|
||||||
)
|
|
||||||
if int(match.get("size") or -1) != path.stat().st_size:
|
|
||||||
raise PublishError(
|
|
||||||
f"draft asset {path.name} size mismatch; refusing to overwrite"
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
upload_asset(api, repo, release_id, path, token_value)
|
|
||||||
|
|
||||||
refreshed = get_release_by_tag(api, repo, tag, token_value)
|
|
||||||
if not refreshed or not published_matches(refreshed, expected):
|
|
||||||
raise PublishError("post-upload release asset list does not match local files")
|
|
||||||
|
|
||||||
published = patch_release(
|
|
||||||
api,
|
|
||||||
repo,
|
|
||||||
release_id,
|
|
||||||
token_value,
|
|
||||||
{"draft": False, "prerelease": prerelease, "name": tag, "body": body},
|
|
||||||
)
|
|
||||||
if published.get("draft"):
|
|
||||||
raise PublishError("release remained draft after publish")
|
|
||||||
final = get_release_by_tag(api, repo, tag, token_value)
|
|
||||||
if not final or final.get("draft") or not published_matches(final, expected):
|
|
||||||
raise PublishError("final release confirmation failed")
|
|
||||||
return {
|
|
||||||
"status": "published",
|
|
||||||
"release_id": final["id"],
|
|
||||||
"html_url": final.get("html_url"),
|
|
||||||
"tag": tag,
|
|
||||||
"assets": expected,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv: list[str] | None = None) -> int:
|
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
|
||||||
parser.add_argument("--api-url", default=os.environ.get("GITEA_API_URL", DEFAULT_API))
|
|
||||||
parser.add_argument("--repo", required=True, help="owner/name")
|
|
||||||
parser.add_argument("--tag", required=True)
|
|
||||||
parser.add_argument("--target", required=True, help="full commit SHA for the tag")
|
|
||||||
parser.add_argument("--body-file", default=None)
|
|
||||||
parser.add_argument("--body", default="")
|
|
||||||
parser.add_argument("--asset", action="append", default=[], required=True)
|
|
||||||
parser.add_argument("--prerelease", action="store_true", default=False)
|
|
||||||
parser.add_argument("--evidence-out", default="dist/gitea-publish-result.json")
|
|
||||||
args = parser.parse_args(argv)
|
|
||||||
body = args.body
|
|
||||||
if args.body_file:
|
|
||||||
body = Path(args.body_file).read_text(encoding="utf-8")
|
|
||||||
assets = [Path(item) for item in args.asset]
|
|
||||||
for path in assets:
|
|
||||||
if not path.is_file():
|
|
||||||
print(f"publish_gitea: FAIL: missing asset {path}", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
try:
|
|
||||||
result = publish(
|
|
||||||
api=args.api_url.rstrip("/"),
|
|
||||||
repo=args.repo,
|
|
||||||
tag=args.tag,
|
|
||||||
body=body,
|
|
||||||
target=args.target,
|
|
||||||
assets=assets,
|
|
||||||
prerelease=args.prerelease,
|
|
||||||
token_value=token(),
|
|
||||||
)
|
|
||||||
except PublishError as error:
|
|
||||||
print(f"publish_gitea: FAIL: {error}", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
out = Path(args.evidence_out)
|
|
||||||
out.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
out.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
||||||
print(json.dumps(result, indent=2, sort_keys=True))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
raise SystemExit(main())
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Write the external release-evidence.json index for a component release.
|
|
||||||
|
|
||||||
The index references already-built assets. It never includes itself in
|
|
||||||
`assets[]` (no self-referential digest). Downstream discoverers hash the index
|
|
||||||
bytes separately when they download it.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
SHA_RE = re.compile(r"^[0-9a-f]{40}$")
|
|
||||||
DIGEST_RE = re.compile(r"^[0-9a-f]{64}$")
|
|
||||||
MAX_ASSETS = 128
|
|
||||||
MAX_DEPENDENCIES = 256
|
|
||||||
INDEX_NAME = "release-evidence.json"
|
|
||||||
|
|
||||||
|
|
||||||
class EvidenceError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def sha256_file(path: Path) -> str:
|
|
||||||
digest = hashlib.sha256()
|
|
||||||
with path.open("rb") as handle:
|
|
||||||
while True:
|
|
||||||
chunk = handle.read(1024 * 1024)
|
|
||||||
if not chunk:
|
|
||||||
break
|
|
||||||
digest.update(chunk)
|
|
||||||
return digest.hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
def parse_dependency(raw: str) -> dict:
|
|
||||||
# id=cli,source_sha=<40hex>[,asset_sha256=<64hex>]
|
|
||||||
fields = {}
|
|
||||||
for part in raw.split(","):
|
|
||||||
if "=" not in part:
|
|
||||||
raise EvidenceError(f"invalid dependency field: {raw!r}")
|
|
||||||
key, value = part.split("=", 1)
|
|
||||||
fields[key.strip()] = value.strip()
|
|
||||||
component_id = fields.get("id")
|
|
||||||
source_sha = fields.get("source_sha")
|
|
||||||
if not component_id or not source_sha or not SHA_RE.match(source_sha):
|
|
||||||
raise EvidenceError(f"dependency requires id and 40-hex source_sha: {raw!r}")
|
|
||||||
entry = {"id": component_id, "source_sha": source_sha}
|
|
||||||
asset = fields.get("asset_sha256")
|
|
||||||
if asset:
|
|
||||||
if not DIGEST_RE.match(asset):
|
|
||||||
raise EvidenceError(f"invalid asset_sha256 in dependency: {raw!r}")
|
|
||||||
entry["asset_sha256"] = asset
|
|
||||||
return entry
|
|
||||||
|
|
||||||
|
|
||||||
def build_evidence(
|
|
||||||
*,
|
|
||||||
component_id: str,
|
|
||||||
repository: str,
|
|
||||||
tag: str,
|
|
||||||
source_sha: str,
|
|
||||||
assets: list[Path],
|
|
||||||
dependencies: list[dict],
|
|
||||||
pipeline_number: int | None,
|
|
||||||
pipeline_url: str | None,
|
|
||||||
) -> dict:
|
|
||||||
if not component_id:
|
|
||||||
raise EvidenceError("component_id is required")
|
|
||||||
if "/" not in repository:
|
|
||||||
raise EvidenceError("repository must be owner/name")
|
|
||||||
if not tag:
|
|
||||||
raise EvidenceError("tag is required")
|
|
||||||
if not SHA_RE.match(source_sha):
|
|
||||||
raise EvidenceError("source_sha must be a 40-hex commit")
|
|
||||||
if not assets:
|
|
||||||
raise EvidenceError("at least one non-index asset is required")
|
|
||||||
if len(assets) > MAX_ASSETS:
|
|
||||||
raise EvidenceError(f"more than {MAX_ASSETS} assets")
|
|
||||||
if len(dependencies) > MAX_DEPENDENCIES:
|
|
||||||
raise EvidenceError(f"more than {MAX_DEPENDENCIES} dependencies")
|
|
||||||
|
|
||||||
asset_entries = []
|
|
||||||
seen_names: set[str] = set()
|
|
||||||
for path in assets:
|
|
||||||
if not path.is_file():
|
|
||||||
raise EvidenceError(f"asset missing: {path}")
|
|
||||||
name = path.name
|
|
||||||
if name == INDEX_NAME:
|
|
||||||
raise EvidenceError("assets must not include release-evidence.json itself")
|
|
||||||
if name in seen_names or "/" in name or name in (".", ".."):
|
|
||||||
raise EvidenceError(f"unsafe or duplicate asset name: {name!r}")
|
|
||||||
seen_names.add(name)
|
|
||||||
target = "source"
|
|
||||||
if name.endswith(".tar.gz") and "linux" in name:
|
|
||||||
target = "x86_64-unknown-linux-gnu"
|
|
||||||
asset_entries.append(
|
|
||||||
{
|
|
||||||
"name": name,
|
|
||||||
"target": target,
|
|
||||||
"size": path.stat().st_size,
|
|
||||||
"sha256": sha256_file(path),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
evidence = {
|
|
||||||
"component_id": component_id,
|
|
||||||
"repository": repository,
|
|
||||||
"tag": tag,
|
|
||||||
"source_sha": source_sha,
|
|
||||||
"ci": {
|
|
||||||
"pipeline_number": pipeline_number,
|
|
||||||
"url": pipeline_url,
|
|
||||||
"source_sha": source_sha,
|
|
||||||
},
|
|
||||||
"assets": asset_entries,
|
|
||||||
"dependencies": dependencies,
|
|
||||||
}
|
|
||||||
return evidence
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv: list[str] | None = None) -> int:
|
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
|
||||||
parser.add_argument("--component-id", required=True)
|
|
||||||
parser.add_argument("--repository", required=True)
|
|
||||||
parser.add_argument("--tag", required=True)
|
|
||||||
parser.add_argument("--source-sha", required=True)
|
|
||||||
parser.add_argument("--asset", action="append", default=[], required=True)
|
|
||||||
parser.add_argument("--dependency", action="append", default=[])
|
|
||||||
parser.add_argument("--pipeline-number", type=int, default=None)
|
|
||||||
parser.add_argument("--pipeline-url", default=None)
|
|
||||||
parser.add_argument("--out", default=f"dist/{INDEX_NAME}")
|
|
||||||
args = parser.parse_args(argv)
|
|
||||||
try:
|
|
||||||
dependencies = [parse_dependency(item) for item in args.dependency]
|
|
||||||
evidence = build_evidence(
|
|
||||||
component_id=args.component_id,
|
|
||||||
repository=args.repository,
|
|
||||||
tag=args.tag,
|
|
||||||
source_sha=args.source_sha,
|
|
||||||
assets=[Path(item) for item in args.asset],
|
|
||||||
dependencies=dependencies,
|
|
||||||
pipeline_number=args.pipeline_number,
|
|
||||||
pipeline_url=args.pipeline_url,
|
|
||||||
)
|
|
||||||
except EvidenceError as error:
|
|
||||||
print(f"write_evidence: FAIL: {error}", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
out = Path(args.out)
|
|
||||||
out.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
payload = json.dumps(evidence, indent=2, sort_keys=True, ensure_ascii=False) + "\n"
|
|
||||||
if len(payload.encode()) > 1024 * 1024:
|
|
||||||
print("write_evidence: FAIL: index exceeds 1 MiB", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
out.write_text(payload, encoding="utf-8")
|
|
||||||
print(out)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
raise SystemExit(main())
|
|
||||||
@@ -157,6 +157,9 @@ def _dig(value, pointer: str):
|
|||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
|
global CASES
|
||||||
|
if os.environ.get("MARQDO_STDLIB_CASES_DIR"):
|
||||||
|
CASES = Path(os.environ["MARQDO_STDLIB_CASES_DIR"]).resolve()
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
parser.add_argument("cases", nargs="*", help="case names to run")
|
parser.add_argument("cases", nargs="*", help="case names to run")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|||||||
Executable
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Candidate-input strict-mode self-test.
|
||||||
|
#
|
||||||
|
# Strict JSON rejects duplicate keys and non-finite numbers. Those symbols only
|
||||||
|
# exist in a Bundle that contains this component's current modules, so this
|
||||||
|
# suite is separate from the default `scripts/test.sh` (which must keep running
|
||||||
|
# against the frozen ecosystem Bundle). Callers pass an explicit candidate
|
||||||
|
# Bundle produced from the current component gitlink, e.g. by the root repo's
|
||||||
|
# `scripts/build-stdlib.py` / acceptance pipeline.
|
||||||
|
set -eu
|
||||||
|
: "${MARQDO_BIN:?set MARQDO_BIN to the verified marqdo executable}"
|
||||||
|
: "${MARQDO_STDLIB_DIR:?set MARQDO_STDLIB_DIR to a candidate Bundle containing current modules}"
|
||||||
|
MARQDO_STDLIB_CASES_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/../tests/cases-strict" && pwd)"
|
||||||
|
export MARQDO_STDLIB_CASES_DIR
|
||||||
|
exec python3 "$(dirname "$0")/run_cases.py" "$@"
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"schema": "marqdo.stdlib-test-case",
|
||||||
|
"schema_version": 1,
|
||||||
|
"name": "json-strict",
|
||||||
|
"file": "json-strict.mq.md",
|
||||||
|
"require_module": "data/json.mq.md",
|
||||||
|
"args": [],
|
||||||
|
"stdin": "",
|
||||||
|
"env": {},
|
||||||
|
"expected_stdout": "",
|
||||||
|
"expected_terminal": {
|
||||||
|
"type": "list",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "bool",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bool",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bool",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"value": "json.duplicate_key"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"value": "json.duplicate_key"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"value": "json.non_finite_number"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"value": "json.non_finite_number"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bool",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bool",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bool",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "map",
|
||||||
|
"entries": {
|
||||||
|
"a": {
|
||||||
|
"type": "int",
|
||||||
|
"decimal": "2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
import:
|
||||||
|
json: "std:data/json"
|
||||||
|
---
|
||||||
|
|
||||||
|
# @exec 严格解析
|
||||||
|
|
||||||
|
## main
|
||||||
|
|
||||||
|
**`合法对象 = json.严格解析("{\"b\":3,\"c\":[1,2.5,true,null]}")`**
|
||||||
|
|
||||||
|
**`合法数组 = json.严格解析("[1,2.5,true,null,\"x\",{\"b\":3}]")`**
|
||||||
|
|
||||||
|
**`重复键 = json.严格解析("{\"a\":1,\"a\":2}")`**
|
||||||
|
|
||||||
|
**`转义等价重复 = json.严格解析("{\"a\":1,\"\\u0061\":2}")`**
|
||||||
|
|
||||||
|
**`溢出 = json.严格解析("1e400")`**
|
||||||
|
|
||||||
|
**`负溢出 = json.严格解析("-1e400")`**
|
||||||
|
|
||||||
|
**`最大量级 = json.严格解析("1.79e308")`**
|
||||||
|
|
||||||
|
**`超出最大量级 = json.严格解析("1.8e308")`**
|
||||||
|
|
||||||
|
**`普通入口 = json.解析("{\"a\":1,\"a\":2}")`**
|
||||||
|
|
||||||
|
`return [合法对象.ok, 合法数组.ok, 重复键.ok, 重复键.code, 转义等价重复.code, 溢出.code, 负溢出.code, 最大量级.ok, 超出最大量级.ok, 普通入口.ok, 普通入口.value]`
|
||||||
Reference in new issue
Block a user