feat(web): land Artifact serve/endpoint path and retire compose golds
Wire data_source into Document render, register Endpoint handlers via run_artifact, restore marqdo-blog as an Artifact site, and replace old compose_* web golds with ADR 0007 fixtures and docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
67bac1bf02
commit
ff252fd469
86 files changed
+952
-4499
No files matched your search
@@ -1,93 +0,0 @@
|
||||
---
|
||||
title: web admin form-from-schema smoke
|
||||
description: Schema-derived admin forms share validate/submit (offline).
|
||||
import web:ext/web/web.mq.md
|
||||
import articles:web-fixtures/db/articles.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/admin-smoke.db"**
|
||||
**schema = > articles.schema**
|
||||
> `store`.init name=articles fields=`schema`
|
||||
> `store`.exec sql="DELETE FROM articles"
|
||||
> `store`.exec sql="DELETE FROM sqlite_sequence WHERE name='articles'"
|
||||
**url = > json.get value=`store` key="url"**
|
||||
|
||||
**info = > web_db_table_info url=`url` table="articles"**
|
||||
**cols = > json.get value=`info` key="columns"**
|
||||
**n = > len value=`cols`**
|
||||
1. `n` >= 2
|
||||
> print text=schema-ok
|
||||
2. *
|
||||
> print text=schema-fail
|
||||
|
||||
**fnew = > web_form_from_schema url=`url` table="articles" action="insert"**
|
||||
**fields = > json.get value=`fnew` key="fields"**
|
||||
**nf = > len value=`fields`**
|
||||
1. `nf` >= 1
|
||||
> print text=new-form-ok
|
||||
2. *
|
||||
> print text=new-form-fail
|
||||
|
||||
`row` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Admin create | via schema form |
|
||||
|
||||
**sub = > web_form_submit form=`fnew` data=`row` url=`url`**
|
||||
**sok = > json.get value=`sub` key="ok"**
|
||||
1. `sok`
|
||||
> print text=insert-ok
|
||||
2. *
|
||||
> print text=insert-fail
|
||||
|
||||
**got = > `store`.get table="articles" id=1**
|
||||
**title = > json.get value=`got` key="title"**
|
||||
1. `title` == "Admin create"
|
||||
> print text=get-ok
|
||||
2. *
|
||||
> print text=get-fail
|
||||
|
||||
**fedit = > web_form_from_schema url=`url` table="articles" action="update" id=1**
|
||||
`patch` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Admin edited | body updated |
|
||||
|
||||
**up = > web_form_submit form=`fedit` data=`patch` url=`url`**
|
||||
**uok = > json.get value=`up` key="ok"**
|
||||
1. `uok`
|
||||
> print text=update-ok
|
||||
2. *
|
||||
> print text=update-fail
|
||||
|
||||
**got2 = > `store`.get table="articles" id=1**
|
||||
**title2 = > json.get value=`got2` key="title"**
|
||||
1. `title2` == "Admin edited"
|
||||
> print text=edit-ok
|
||||
2. *
|
||||
> print text=edit-fail
|
||||
|
||||
`empty` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| | |
|
||||
|
||||
**bad = > web_form_submit form=`fnew` data=`empty` url=`url`**
|
||||
**bok = > json.get value=`bad` key="ok"**
|
||||
1. `bok`
|
||||
> print text=required-should-fail
|
||||
2. *
|
||||
> print text=required-ok
|
||||
|
||||
**errs = > json.get value=`bad` key="errors"**
|
||||
**nerr = > len value=`errs`**
|
||||
1. `nerr` >= 1
|
||||
> print text=errors-echoed-ok
|
||||
2. *
|
||||
> print text=errors-echoed-fail
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
type: endpoint
|
||||
method: GET
|
||||
path: /api/ping
|
||||
request: none
|
||||
response: json
|
||||
auth: none
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`out` =
|
||||
|
||||
| ok | ping |
|
||||
|----|------|
|
||||
| True | pong |
|
||||
|
||||
*out*
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
type: web
|
||||
title: Artifact site
|
||||
route: /
|
||||
method: GET
|
||||
---
|
||||
|
||||
# Artifact site
|
||||
|
||||
Home Document for live Endpoint tests.
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
type: web
|
||||
title: About
|
||||
route: /about
|
||||
method: GET
|
||||
---
|
||||
|
||||
# About
|
||||
|
||||
Declared Document route.
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
title: artifact site serve
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
> web.serve root="." host="127.0.0.1" port=18110
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
title: web assets live server
|
||||
description: Live favicon + head icon + images_html on home page.
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`icons_table` =
|
||||
|
||||
|path|rel|type|url|
|
||||
|---|---|---|---|
|
||||
|"web-fixtures/public/favicon.png"|icon|"image/png"|"/favicon.ico"|
|
||||
|
||||
`head_table` =
|
||||
|
||||
|rel|href|type|
|
||||
|---|---|---|
|
||||
|apple-touch-icon|"/static/favicon.png"|"image/png"|
|
||||
|
||||
`images_table` =
|
||||
|
||||
|src|alt|class|loading|
|
||||
|---|---|---|---|
|
||||
|"/static/favicon.svg"|mark|brand|eager|
|
||||
|
||||
**home = > web.page title="Live assets" intro="<p>assets live</p>"**
|
||||
**home = > `home`.head table=`head_table`**
|
||||
**home = > `home`.images table=`images_table`**
|
||||
|
||||
**app = > web.app page=`home` host=127.0.0.1 port=18092**
|
||||
**app = > `app`.static dir="web-fixtures/public" mount="/static"**
|
||||
**app = > `app`.icons table=`icons_table`**
|
||||
|
||||
> print text=marqdo web assets live starting
|
||||
> `app`.listen
|
||||
@@ -1,92 +0,0 @@
|
||||
---
|
||||
title: web assets smoke
|
||||
description: Offline icons / head / images assembly (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`icons_table` =
|
||||
|
||||
|path|rel|type|sizes|url|
|
||||
|---|---|---|---|---|
|
||||
|"web-fixtures/public/favicon.png"|icon|"image/png"|32x32|"/favicon.ico"|
|
||||
|"web-fixtures/public/favicon.svg"|icon|"image/svg+xml"|any|"/static/favicon.svg"|
|
||||
|
||||
`head_table` =
|
||||
|
||||
|rel|href|type|media|
|
||||
|---|---|---|---|
|
||||
|icon|"/favicon.ico"|"image/png"|
|
||||
|stylesheet|"/static/print.css"|"text/css"|print|
|
||||
|script|"/static/live.js"||
|
||||
|
||||
`images_table` =
|
||||
|
||||
|src|alt|class|href|width|loading|caption|
|
||||
|---|---|---|---|---|---|---|
|
||||
|"/static/logo.svg"|Marqdo|brand-logo|"/"|48|eager|Brand|
|
||||
|
||||
`seo` =
|
||||
|
||||
| 行 | key | value |
|
||||
|----|-----|-------|
|
||||
| 1 | description | asset smoke |
|
||||
| 2 | icon | "/favicon.ico" |
|
||||
| 3 | og:image | "/static/logo.svg" |
|
||||
|
||||
**home = > web.page title="Assets"**
|
||||
**home = > `home`.head table=`head_table`**
|
||||
**home = > `home`.images table=`images_table`**
|
||||
**home = > `home`.meta meta=`seo`**
|
||||
|
||||
**ih = > json.get value=`home` key="images_html"**
|
||||
1. `ih` != ""
|
||||
> print text=images-ok
|
||||
2. *
|
||||
> print text=images-fail
|
||||
|
||||
**hd = > json.get value=`home` key="head"**
|
||||
**n = > len `hd`**
|
||||
1. `n` >= 3
|
||||
> print text=head-ok
|
||||
2. *
|
||||
> print text=head-fail
|
||||
|
||||
**meta = > json.get value=`home` key="meta"**
|
||||
**icon = > json.get value=`meta` key="icon"**
|
||||
1. `icon` == "/favicon.ico"
|
||||
> print text=meta-icon-ok
|
||||
2. *
|
||||
> print text=meta-icon-fail
|
||||
|
||||
**app = > web.app page=`home` host=127.0.0.1 port=18091**
|
||||
**app = > `app`.static dir="web-fixtures/public" mount="/static"**
|
||||
**app = > `app`.icons table=`icons_table`**
|
||||
|
||||
**icons = > json.get value=`app` key="icons"**
|
||||
**ni = > len `icons`**
|
||||
1. `ni` == 2
|
||||
> print text=icons-ok
|
||||
2. *
|
||||
> print text=icons-fail
|
||||
|
||||
**sh = > json.get value=`app` key="site_head"**
|
||||
**ns = > len `sh`**
|
||||
1. `ns` >= 1
|
||||
> print text=site-head-ok
|
||||
2. *
|
||||
> print text=site-head-fail
|
||||
|
||||
**preview = > web.make_images table=`images_table`**
|
||||
1. `preview` != ""
|
||||
> print text=make-images-ok
|
||||
2. *
|
||||
> print text=make-images-fail
|
||||
|
||||
**hprev = > web.make_head table=`head_table`**
|
||||
1. `hprev` != ""
|
||||
> print text=make-head-ok
|
||||
2. *
|
||||
> print text=make-head-fail
|
||||
@@ -1,25 +0,0 @@
|
||||
---
|
||||
title: web-auth-custom-page
|
||||
description: Custom branded login owns GET /login; POST failure re-renders same shell with CSRF; no author JS.
|
||||
import 网页:ext/web/网页.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`用户` =
|
||||
|
||||
| 行 | 用户名 | 密码 |
|
||||
|----|--------|------|
|
||||
| 1 | alice | secret12 |
|
||||
|
||||
**page = > 网页.页面 标题="Home" 引言="<p>home</p>"**
|
||||
**login = > 网页.页面 标题="登录" 引言="<div class='panel'><h1>登录</h1><div id='auth-mount'></div></div>"**
|
||||
**login = > login.鉴权表单 动作="/login" 提交="登录" 表单id="login-form" 错误id="login-err" 表单插槽="#auth-mount" 种类="login"**
|
||||
|
||||
**db = > 网页.数据库**
|
||||
**app = > 网页.应用 页面=page 数据库=db 后台=假 主机="127.0.0.1" 端口=0**
|
||||
**app = > app.路由 路径="/login" 页面=login**
|
||||
**app = > app.鉴权 用户表=`用户` 会话时长=3600 登录路径="/login" 登录回跳="/"**
|
||||
|
||||
> print text=web-auth-custom-page ok
|
||||
*None*
|
||||
@@ -1,72 +0,0 @@
|
||||
---
|
||||
title: web C0 admin prefix / route release
|
||||
description: admin=False frees /admin; custom admin_prefix reserves only that mount.
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**首页 = > web.page title="home"**
|
||||
**页 = > web.page title="news"**
|
||||
|
||||
**应用 = > web.app page=`首页` admin=False**
|
||||
**应用 = > `应用`.route path="/admin/news" page=`页`**
|
||||
**routes = > json.get value=`应用` key="routes"**
|
||||
**hit = > json.get value=`routes` key="/admin/news"**
|
||||
1. `hit`
|
||||
> print text=free-admin-ok
|
||||
2. *
|
||||
> print text=free-admin-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**应用3 = > web.app page=`首页` admin=True admin_prefix="/desk"**
|
||||
**应用3 = > `应用3`.route path="/admin/news" page=`页`**
|
||||
**routes3 = > json.get value=`应用3` key="routes"**
|
||||
**hit3 = > json.get value=`routes3` key="/admin/news"**
|
||||
1. `hit3`
|
||||
> print text=prefix-frees-admin-ok
|
||||
2. *
|
||||
> print text=prefix-frees-admin-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**prefix = > json.get value=`应用3` key="admin_prefix"**
|
||||
1. `prefix` == "/desk"
|
||||
> print text=prefix-stored-ok
|
||||
2. *
|
||||
> print text=prefix-stored-fail
|
||||
> sys.exit code=1
|
||||
|
||||
`用户表` =
|
||||
| 用户名 | 密码 | 角色 |
|
||||
|--------|------|------|
|
||||
| admin | secret | admin |
|
||||
|
||||
**应用4 = > web.app page=`首页` admin=True**
|
||||
**应用4 = > `应用4`.auth users=`用户表` admin_prefix="/desk" login_redirect="/desk" logout_redirect="/desk/login"**
|
||||
**prefix4 = > json.get value=`应用4` key="admin_prefix"**
|
||||
**login4 = > json.get value=`应用4` key="login_redirect"**
|
||||
**logout4 = > json.get value=`应用4` key="logout_redirect"**
|
||||
**gates = > json.get value=`应用4` key="gates"**
|
||||
**g0 = > at value=`gates` index=0**
|
||||
**gpath = > json.get value=`g0` key="path"**
|
||||
1. `prefix4` == "/desk"
|
||||
1. `login4` == "/desk"
|
||||
1. `logout4` == "/desk/login"
|
||||
1. `gpath` == "/desk"
|
||||
> print text=auth-prefix-ok
|
||||
2. *
|
||||
> print text=auth-gate-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-logout-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-login-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-prefix-fail
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=c0-admin-ok
|
||||
@@ -1,81 +0,0 @@
|
||||
---
|
||||
title: web C1 gate match / on_deny / exclude
|
||||
description: Segment-boundary prefix; auth default redirect; custom gate fields.
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**首页 = > web.page title="home"**
|
||||
|
||||
`用户表` =
|
||||
| 用户名 | 密码 | 角色 |
|
||||
|--------|------|------|
|
||||
| admin | secret | admin |
|
||||
|
||||
**应用 = > web.app page=`首页` admin=True**
|
||||
**应用 = > `应用`.auth users=`用户表`**
|
||||
**gates = > json.get value=`应用` key="gates"**
|
||||
**g0 = > at value=`gates` index=0**
|
||||
**path = > json.get value=`g0` key="path"**
|
||||
**match = > json.get value=`g0` key="match"**
|
||||
**deny = > json.get value=`g0` key="on_deny"**
|
||||
**login = > json.get value=`应用` key="login_path"**
|
||||
1. `path` == "/admin"
|
||||
1. `match` == "prefix"
|
||||
1. `deny` == "redirect"
|
||||
1. `login` == "/admin/login"
|
||||
> print text=auth-default-gate-ok
|
||||
2. *
|
||||
> print text=login-path-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=on-deny-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=match-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=path-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**应用2 = > web.app page=`首页` admin=False**
|
||||
**应用2 = > `应用2`.gate path="/desk" roles="admin" match="prefix" on_deny="redirect" exclude="/desk/login"**
|
||||
**gates2 = > json.get value=`应用2` key="gates"**
|
||||
**g1 = > at value=`gates2` index=0**
|
||||
**p2 = > json.get value=`g1` key="path"**
|
||||
**m2 = > json.get value=`g1` key="match"**
|
||||
**d2 = > json.get value=`g1` key="on_deny"**
|
||||
**ex = > json.get value=`g1` key="exclude"**
|
||||
1. `p2` == "/desk"
|
||||
1. `m2` == "prefix"
|
||||
1. `d2` == "redirect"
|
||||
1. `ex`
|
||||
> print text=custom-gate-ok
|
||||
2. *
|
||||
> print text=exclude-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=custom-deny-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=custom-match-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=custom-path-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**应用3 = > web.app page=`首页` admin=False**
|
||||
**应用3 = > `应用3`.gate path="/write*" roles="admin,author"**
|
||||
**gates3 = > json.get value=`应用3` key="gates"**
|
||||
**g3 = > at value=`gates3` index=0**
|
||||
**p3 = > json.get value=`g3` key="path"**
|
||||
1. `p3`
|
||||
> print text=star-gate-ok
|
||||
2. *
|
||||
> print text=star-gate-fail
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=c1-gate-ok
|
||||
@@ -1,60 +0,0 @@
|
||||
---
|
||||
title: web C2 shell_css + layout
|
||||
description: Offline render markers for shell modes and layouts.
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`链` =
|
||||
| 标签 | 链接 |
|
||||
|------|------|
|
||||
| Home | / |
|
||||
| Desk | /desk |
|
||||
|
||||
**页 = > web.page title="c2" shell_css="off" layout="stacked"**
|
||||
**页 = > json.set map=`页` key="nav" value=`链`**
|
||||
**页 = > json.set map=`页` key="sidebar" value=`链`**
|
||||
**html = > `页`.render**
|
||||
|
||||
**a = > split value=`html` sep="layout-stacked"**
|
||||
**na = > len value=`a`**
|
||||
**b = > split value=`html` sep="has-sidebar"**
|
||||
**nb = > len value=`b`**
|
||||
**c = > split value=`html` sep="grid-template-columns:14rem"**
|
||||
**nc = > len value=`c`**
|
||||
1. `na` > 1
|
||||
1. `nb` == 1
|
||||
1. `nc` == 1
|
||||
> print text=stacked-off-ok
|
||||
2. *
|
||||
> print text=grid-still-present
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=has-sidebar-leak
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=stacked-missing
|
||||
> sys.exit code=1
|
||||
|
||||
**裸 = > web.page title="bare" layout="bare" shell_css="minimal"**
|
||||
**裸 = > json.set map=`裸` key="nav" value=`链`**
|
||||
**裸 = > json.set map=`裸` key="sidebar" value=`链`**
|
||||
**h2 = > `裸`.render**
|
||||
**d = > split value=`h2` sep="<aside"**
|
||||
**nd = > len value=`d`**
|
||||
**e = > split value=`h2` sep="--ink:"**
|
||||
**ne = > len value=`e`**
|
||||
1. `nd` == 1
|
||||
1. `ne` > 1
|
||||
> print text=bare-minimal-ok
|
||||
2. *
|
||||
> print text=minimal-vars-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=bare-aside-leak
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=c2-shell-ok
|
||||
@@ -1,91 +0,0 @@
|
||||
---
|
||||
title: web C3 style strict + head defer/version
|
||||
description: Offline markers for quoted CSS cells and head script lifecycle.
|
||||
import web:ext/web/web.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`好` =
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| .box | grid-column | "1 / 5" |
|
||||
|
||||
**css = > web.make_style name="t" table=`好` strict=True**
|
||||
**a = > split value=`css` sep="1 / 5"**
|
||||
**na = > len value=`a`**
|
||||
1. `na` > 1
|
||||
> print text=quoted-css-ok
|
||||
2. *
|
||||
> print text=quoted-css-missing
|
||||
> sys.exit code=1
|
||||
|
||||
`头` =
|
||||
| 关系 | 地址 | 推迟 | 版本 |
|
||||
|------|------|------|------|
|
||||
| script | /static/a.js | 真 | 3 |
|
||||
| stylesheet | /static/t.css | | 1 |
|
||||
|
||||
**页 = > web.page title="c3" asset_version="appv"**
|
||||
**页 = > `页`.head table=`头`**
|
||||
**html = > `页`.render**
|
||||
**b = > split value=`html` sep="a.js?v=3"**
|
||||
**nb = > len value=`b`**
|
||||
**c = > split value=`html` sep="t.css?v=1"**
|
||||
**nc = > len value=`c`**
|
||||
**d0 = > split value=`html` sep="script defer"**
|
||||
**nd0 = > len value=`d0`**
|
||||
1. `nb` > 1
|
||||
1. `nc` > 1
|
||||
1. `nd0` > 1
|
||||
> print text=defer-version-ok
|
||||
2. *
|
||||
> print text=defer-attr-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=css-version-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=defer-script-missing
|
||||
> sys.exit code=1
|
||||
|
||||
`头2` =
|
||||
| 关系 | 地址 | 推迟 |
|
||||
|------|------|------|
|
||||
| script | /static/b.js | 真 |
|
||||
|
||||
**页2 = > web.page title="c3b" asset_version="2026-09-04"**
|
||||
**页2 = > `页2`.head table=`头2`**
|
||||
**h2 = > `页2`.render**
|
||||
**d = > split value=`h2` sep="b.js?v=2026-09-04"**
|
||||
**nd = > len value=`d`**
|
||||
1. `nd` > 1
|
||||
> print text=asset-version-ok
|
||||
2. *
|
||||
> print text=asset-version-missing
|
||||
> sys.exit code=1
|
||||
|
||||
`头3` =
|
||||
| 关系 | 地址 |
|
||||
|------|------|
|
||||
| script | /static/sync.js |
|
||||
|
||||
**页3 = > web.page title="c3c"**
|
||||
**页3 = > `页3`.head table=`头3`**
|
||||
**h3 = > `页3`.render**
|
||||
**e = > split value=`h3` sep="sync.js"**
|
||||
**ne = > len value=`e`**
|
||||
**f = > split value=`h3` sep="script defer"**
|
||||
**nf = > len value=`f`**
|
||||
1. `ne` > 1
|
||||
1. `nf` == 1
|
||||
> print text=sync-compat-ok
|
||||
2. *
|
||||
> print text=unexpected-defer
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=sync-script-missing
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=c3-style-head-ok
|
||||
@@ -1,75 +0,0 @@
|
||||
---
|
||||
title: web C4 conditional nav when/media
|
||||
description: Offline render markers for nav when= and media= columns.
|
||||
import web:ext/web/web.mq.md
|
||||
import table:lib/table.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`链` =
|
||||
| 属性 | 值 | 样式 | 媒体 | 当 |
|
||||
|------|-----|------|------|-----|
|
||||
| Home | / | | | |
|
||||
| Desk | /desk | | (max-width: 720px) | |
|
||||
| Admin | /admin | | | auth |
|
||||
| Login | /login | | | guest |
|
||||
| Gone | /gone | | | hide |
|
||||
|
||||
**客 = > web.page title="c4-guest" shell_css="off"**
|
||||
**`客` = > table.put in=`客` at="nav" value=`链`**
|
||||
**`客` = > table.put in=`客` at="_logged_in" value=False**
|
||||
**hg = > `客`.render**
|
||||
|
||||
**a = > split value=`hg` sep="/login"**
|
||||
**na = > len value=`a`**
|
||||
**b = > split value=`hg` sep="/admin"**
|
||||
**nb = > len value=`b`**
|
||||
**c = > split value=`hg` sep="/gone"**
|
||||
**nc = > len value=`c`**
|
||||
**d = > split value=`hg` sep="nav-mq-0"**
|
||||
**nd = > len value=`d`**
|
||||
**e = > split value=`hg` sep="@media not (max-width: 720px)"**
|
||||
**ne = > len value=`e`**
|
||||
1. `na` > 1
|
||||
1. `nb` == 1
|
||||
1. `nc` == 1
|
||||
1. `nd` > 1
|
||||
1. `ne` > 1
|
||||
> print text=guest-media-ok
|
||||
2. *
|
||||
> print text=media-css-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=media-class-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=hide-leaked
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-leaked-for-guest
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=guest-login-missing
|
||||
> sys.exit code=1
|
||||
|
||||
**户 = > web.page title="c4-user" shell_css="off"**
|
||||
**`户` = > table.put in=`户` at="nav" value=`链`**
|
||||
**`户` = > table.put in=`户` at="_logged_in" value=True**
|
||||
**hu = > `户`.render**
|
||||
**f = > split value=`hu` sep="/admin"**
|
||||
**nf = > len value=`f`**
|
||||
**g = > split value=`hu` sep="/login"**
|
||||
**ng = > len value=`g`**
|
||||
1. `nf` > 1
|
||||
1. `ng` == 1
|
||||
> print text=auth-ok
|
||||
2. *
|
||||
> print text=guest-leaked-for-user
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-admin-missing
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=c4-nav-ok
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: ext/data cache smoke
|
||||
import cache:ext/data/cache.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**c = > cache.cache url="memory:"**
|
||||
> `c`.set key="k" value="v" ttl=60
|
||||
**got = > `c`.get key="k"**
|
||||
**val = [value](got)**
|
||||
1. `val` == "v"
|
||||
> print text=cache-ok
|
||||
2. *
|
||||
> print text=cache-fail
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
title: web collab bag smoke
|
||||
description: route_ws room+presence for collab doc
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**首页 = > web.page title="c"**
|
||||
**应用 = > web.app page=`首页` admin=False**
|
||||
**应用 = > `应用`.route_ws path="/live/{id}" mode="room" room_key="doc.{id}" presence=True**
|
||||
**routes = > json.get value=`应用` key="ws_routes"**
|
||||
**spec = > json.get value=`routes` key="/live/{id}"**
|
||||
**mode = > json.get value=`spec` key="mode"**
|
||||
**pr = > json.get value=`spec` key="presence"**
|
||||
1. `mode` == "room"
|
||||
1. `pr` == True
|
||||
> print text=collab-ws-bag-ok
|
||||
2. *
|
||||
> print text=presence-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=mode-fail
|
||||
> sys.exit code=1
|
||||
@@ -1,51 +0,0 @@
|
||||
---
|
||||
title: web content smoke (W4)
|
||||
description: SEO meta + paginate bag (offline ABI).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
`meta` =
|
||||
|
||||
| 行 | 键 | 值 |
|
||||
|----|-----|-----|
|
||||
| 1 | title | My Site |
|
||||
| 2 | description | A demo site |
|
||||
| 3 | og:type | website |
|
||||
|
||||
**page = > web.page title="Home"**
|
||||
**page = > page.meta meta=`meta`**
|
||||
**mm = [meta](page)**
|
||||
**m = [title](mm)**
|
||||
1. `m` == "My Site"
|
||||
> print text=meta-ok
|
||||
2. *
|
||||
> print text=meta-fail
|
||||
|
||||
**page = > page.paginate offset=0 limit=5 path="/"**
|
||||
**poff = [offset]([paginate](page))**
|
||||
1. `poff` == 0
|
||||
> print text=paginate-ok
|
||||
2. *
|
||||
> print text=paginate-fail
|
||||
|
||||
`rows` =
|
||||
|
||||
| 行 | title | slug | summary |
|
||||
|----|-------|------|---------|
|
||||
| 1 | Hello | /a | First post |
|
||||
|
||||
**feed = > web_rss_build title="Blog" link="http://example.com" description="Demo" items=`rows`**
|
||||
1. `feed` != ""
|
||||
> print text=rss-ok
|
||||
2. *
|
||||
> print text=rss-fail
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
title: web db cross-module lib
|
||||
description: Opens sqlite, inits a tiny table, returns the db handle.
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
## open
|
||||
|
||||
**store = > web.db url="sqlite::memory:"**
|
||||
|
||||
`fields` =
|
||||
|
||||
| name | type |
|
||||
|------|------|
|
||||
| title | text |
|
||||
|
||||
> `store`.init name=items fields=`fields`
|
||||
|
||||
`seed` =
|
||||
|
||||
| @ | title |
|
||||
|---|-------|
|
||||
| 1 | hello |
|
||||
|
||||
> `store`.insert table=items rows=`seed`
|
||||
*store*
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
title: web db cross-module smoke
|
||||
description: Return a web.db handle from an imported module and call select in the entry module.
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import storemod:web-db-cross-module-lib.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**store = > storemod.open**
|
||||
**rows = > `store`.select table="items" limit=10**
|
||||
**n = > len value=`rows`**
|
||||
1. `n` >= 1
|
||||
> print text=cross-db-ok
|
||||
2. *
|
||||
> print text=cross-db-fail
|
||||
@@ -1,146 +0,0 @@
|
||||
---
|
||||
title: web db W2 smoke — 事务 / 分页 / 原生查询 / 计数 / 查询表达力
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/w2-smoke.db"**
|
||||
|
||||
`字段` =
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| title | text | 否 |
|
||||
| body | text | 是 |
|
||||
| views | int | 是 |
|
||||
|
||||
> `store`.init name=posts fields=`字段`
|
||||
> `store`.exec sql="DELETE FROM posts"
|
||||
|
||||
`数据` =
|
||||
|
||||
| title | body | views |
|
||||
|-------|------|-------|
|
||||
| Alpha | first | 10 |
|
||||
| Beta | second | 20 |
|
||||
| Gamma | third | 30 |
|
||||
| Delta | fourth | 40 |
|
||||
|
||||
> `store`.insert table=posts rows=`数据`
|
||||
|
||||
**c = > `store`.count table="posts"**
|
||||
1. `c` == 4
|
||||
> print text=count-ok
|
||||
2. *
|
||||
> print text=count-fail
|
||||
|
||||
`视图条件` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| views | = | 30 |
|
||||
|
||||
**c2 = > `store`.count table="posts" where=`视图条件`**
|
||||
1. `c2` == 1
|
||||
> print text=count-where-ok
|
||||
2. *
|
||||
> print text=count-where-fail
|
||||
|
||||
**page1 = > `store`.paginate table="posts" limit=2 跳过=0**
|
||||
**total1 = [total](page1)**
|
||||
**p1r = [rows](page1)**
|
||||
**n1 = > len value=`p1r`**
|
||||
1. `total1` == 4
|
||||
1. `n1` == 2
|
||||
> print text=page-ok
|
||||
2. *
|
||||
> print text=page-fail
|
||||
|
||||
**page2 = > `store`.paginate table="posts" limit=2 跳过=2**
|
||||
**p2r = [rows](page2)**
|
||||
**n2 = > len value=`p2r`**
|
||||
1. `n2` == 2
|
||||
> print text=page2-ok
|
||||
2. *
|
||||
> print text=page2-fail
|
||||
|
||||
`in条件` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| title | in | "Alpha,Beta" |
|
||||
|
||||
**in_rows = > `store`.select table="posts" where=`in条件` limit=10**
|
||||
**nin = > len value=`in_rows`**
|
||||
1. `nin` == 2
|
||||
> print text=in-ok
|
||||
2. *
|
||||
> print text=in-fail
|
||||
|
||||
`between条件` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| views | between | "20,35" |
|
||||
|
||||
**bt_rows = > `store`.select table="posts" where=`between条件` limit=10**
|
||||
**nbt = > len value=`bt_rows`**
|
||||
1. `nbt` == 2
|
||||
> print text=between-ok
|
||||
2. *
|
||||
> print text=between-fail
|
||||
|
||||
`or条件` =
|
||||
|
||||
| 字段 | 操作 | 值 | 或 |
|
||||
|------|------|-----|-----|
|
||||
| title | = | Alpha | |
|
||||
| title | = | Gamma | 是 |
|
||||
|
||||
**or_rows = > `store`.select table="posts" where=`or条件` limit=10**
|
||||
**nor = > len value=`or_rows`**
|
||||
1. `nor` == 2
|
||||
> print text=or-ok
|
||||
2. *
|
||||
> print text=or-fail
|
||||
|
||||
**agg = > `store`.query sql="SELECT title, views FROM posts WHERE views >= 30 ORDER BY views DESC"**
|
||||
**nagg = [count](agg)**
|
||||
1. `nagg` == 2
|
||||
> print text=query-ok
|
||||
2. *
|
||||
> print text=query-fail
|
||||
|
||||
**txn = > `store`.事务**
|
||||
`更多` =
|
||||
|
||||
| title | body | views |
|
||||
|-------|------|-------|
|
||||
| Epsilon | fifth | 50 |
|
||||
|
||||
> `txn`.insert table=posts rows=`更多`
|
||||
> `txn`.提交
|
||||
|
||||
**c5 = > `store`.count table="posts"**
|
||||
1. `c5` == 5
|
||||
> print text=txn-commit-ok
|
||||
2. *
|
||||
> print text=txn-commit-fail
|
||||
|
||||
**txn2 = > `store`.事务**
|
||||
`更多2` =
|
||||
|
||||
| title | body | views |
|
||||
|-------|------|-------|
|
||||
| Zeta | sixth | 60 |
|
||||
|
||||
> `txn2`.insert table=posts rows=`更多2`
|
||||
> `txn2`.回滚
|
||||
|
||||
**c6 = > `store`.count table="posts"**
|
||||
1. `c6` == 5
|
||||
> print text=txn-rollback-ok
|
||||
2. *
|
||||
> print text=txn-rollback-fail
|
||||
@@ -1,83 +0,0 @@
|
||||
---
|
||||
title: web db W6 smoke — migrate / FTS5 / published filter
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/w6-smoke.db"**
|
||||
|
||||
`steps` =
|
||||
|
||||
| 版本 | SQL |
|
||||
|------|-----|
|
||||
| 1 | CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, body TEXT, status TEXT NOT NULL DEFAULT 'draft') |
|
||||
| 2 | CREATE TABLE IF NOT EXISTS comments (id INTEGER PRIMARY KEY AUTOINCREMENT, post_id INTEGER NOT NULL, body TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending') |
|
||||
|
||||
**m1 = > `store`.migrate steps=`steps`**
|
||||
**a1 = [applied](m1)**
|
||||
**n1 = > len value=`a1`**
|
||||
1. `n1` == 2
|
||||
> print text=migrate-ok
|
||||
2. *
|
||||
> print text=migrate-fail
|
||||
|
||||
**m2 = > `store`.migrate steps=`steps`**
|
||||
**a2 = [applied](m2)**
|
||||
**n2 = > len value=`a2`**
|
||||
1. `n2` == 0
|
||||
> print text=migrate-idempotent-ok
|
||||
2. *
|
||||
> print text=migrate-idempotent-fail
|
||||
|
||||
`rows` =
|
||||
|
||||
| title | body | status |
|
||||
|-------|------|--------|
|
||||
| Alpha note | hello world search | published |
|
||||
| Beta draft | secret draft body | draft |
|
||||
| Gamma published | another hello | published |
|
||||
|
||||
> `store`.insert table=posts rows=`rows`
|
||||
|
||||
`pub` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| status | = | published |
|
||||
|
||||
**pc = > `store`.count table="posts" where=`pub`**
|
||||
1. `pc` == 2
|
||||
> print text=published-filter-ok
|
||||
2. *
|
||||
> print text=published-filter-fail
|
||||
|
||||
`comments` =
|
||||
|
||||
| post_id | body | status |
|
||||
|---------|------|--------|
|
||||
| 1 | nice post | approved |
|
||||
| 1 | spam | pending |
|
||||
|
||||
> `store`.insert table=comments rows=`comments`
|
||||
**cc = > `store`.count table="comments"**
|
||||
1. `cc` == 2
|
||||
> print text=comments-ok
|
||||
2. *
|
||||
> print text=comments-fail
|
||||
|
||||
> `store`.fts table="posts" columns="title,body"
|
||||
**hit = > `store`.search table="posts" q="hello" limit=10**
|
||||
**hn = [count](hit)**
|
||||
1. `hn` >= 1
|
||||
> print text=fts-ok
|
||||
2. *
|
||||
> print text=fts-fail
|
||||
|
||||
**rows2 = [rows](hit)**
|
||||
**first = [1](rows2)**
|
||||
**ft = [title](first)**
|
||||
1. `ft`
|
||||
> print text=fts-row-ok
|
||||
2. *
|
||||
> print text=fts-row-fail
|
||||
@@ -1,72 +0,0 @@
|
||||
---
|
||||
title: web drivers smoke (W4)
|
||||
description: memory cache + file storage + postgres URL shape (offline).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
<!-- cache: memory backend -->
|
||||
|
||||
**c = > web.cache url="memory:drivers-smoke"**
|
||||
> `c`.set key="k1" value="v1" ttl=60
|
||||
**g = > `c`.get key="k1"**
|
||||
**gv = [value](g)**
|
||||
1. `gv` == "v1"
|
||||
> print text=cache-ok
|
||||
2. *
|
||||
> print text=cache-fail
|
||||
|
||||
> `c`.del key="k1"
|
||||
**ex = > `c`.exists key="k1"**
|
||||
**eok = [ok](ex)**
|
||||
1. `eok`
|
||||
> print text=cache-del-fail
|
||||
2. *
|
||||
> print text=cache-del-ok
|
||||
|
||||
<!-- storage: file backend -->
|
||||
|
||||
**blob = > web.storage url="file:tests/ext/web-fixtures/data/drivers-blobs"**
|
||||
> `blob`.put key="notes/a.txt" body="hello" content_type="text/plain"
|
||||
**got = > `blob`.get key="notes/a.txt"**
|
||||
**body = [body](got)**
|
||||
1. `body` == "hello"
|
||||
> print text=storage-ok
|
||||
2. *
|
||||
> print text=storage-fail
|
||||
|
||||
**ls = > `blob`.list prefix="notes/"**
|
||||
**n = [count](ls)**
|
||||
1. `n` == 1
|
||||
> print text=storage-list-ok
|
||||
2. *
|
||||
> print text=storage-list-fail
|
||||
|
||||
> `blob`.delete key="notes/a.txt"
|
||||
|
||||
<!-- db: postgres URL is accepted as a handle (no live server required) -->
|
||||
|
||||
**pg = > web.db url="postgres://marqdo:marqdo@127.0.0.1:5432/marqdo"**
|
||||
**purl = [url](pg)**
|
||||
1. `purl` == "postgres://marqdo:marqdo@127.0.0.1:5432/marqdo"
|
||||
> print text=postgres-url-ok
|
||||
2. *
|
||||
> print text=postgres-url-fail
|
||||
|
||||
<!-- s3 URL shape validates at open -->
|
||||
|
||||
**s3 = > web.storage url="s3://bucket?endpoint=http://127.0.0.1:9000"**
|
||||
**sb = [backend](s3)**
|
||||
1. `sb` == "s3"
|
||||
> print text=s3-open-ok
|
||||
2. *
|
||||
> print text=s3-open-fail
|
||||
@@ -1,39 +0,0 @@
|
||||
---
|
||||
title: web entry-dir relative path smoke
|
||||
description: Relative db path resolves against the entry script dir, not cwd.
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!--
|
||||
Run from a different cwd than the script dir (e.g. repo root):
|
||||
the sqlite file must land under <script dir>/entrydir-fixtures/data,
|
||||
NOT under the process cwd.
|
||||
-->
|
||||
|
||||
**store = > web.db url="sqlite:entrydir-fixtures/data/entrydir.db"**
|
||||
|
||||
`schema` =
|
||||
|
||||
| 字段 | 类型 |
|
||||
|------|------|
|
||||
| title | text |
|
||||
|
||||
> `store`.init name=items fields=`schema`
|
||||
|
||||
`one` =
|
||||
|
||||
| 行 | title |
|
||||
|----|-------|
|
||||
| 1 | hello |
|
||||
|
||||
> `store`.insert table=items rows=`one`
|
||||
|
||||
**rows = > `store`.select table="items" limit=10**
|
||||
**n = > len value=`rows`**
|
||||
|
||||
1. `n` == 1
|
||||
> print text=entrydir-db-ok
|
||||
2. *
|
||||
> print text=entrydir-db-fail
|
||||
@@ -1,33 +0,0 @@
|
||||
---
|
||||
title: web form embed smoke
|
||||
description: Offline page.compose_form embeds form in main HTML (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`fields` =
|
||||
|
||||
| 字段 | 标签 | 类型 | 必填 | 默认 |
|
||||
|------|------|------|------|------|
|
||||
| title | Title | text | true | |
|
||||
| body | Body | textarea | false | |
|
||||
|
||||
**f = > web.form table="articles" action="insert"**
|
||||
**f = > `f`.fields fields=`fields`**
|
||||
|
||||
**page = > web.page title="Compose" intro="<h1>Compose</h1>"**
|
||||
**page = > `page`.compose_form id="article" form=`f`**
|
||||
|
||||
**fid = > json.get value=`page` key="form_id"**
|
||||
1. `fid`
|
||||
> print text=form-id-ok
|
||||
2. *
|
||||
> print text=form-id-fail
|
||||
|
||||
**html = > `page`.render**
|
||||
1. `html`
|
||||
> print text=render-ok
|
||||
2. *
|
||||
> print text=render-fail
|
||||
@@ -1,43 +0,0 @@
|
||||
---
|
||||
title: web form slot smoke
|
||||
description: compose_form target= mounts form inside intro HTML (GAP-11).
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import text:lib/text.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`fields` =
|
||||
|
||||
| 字段 | 标签 | 类型 | 必填 | 默认 |
|
||||
|------|------|------|------|------|
|
||||
| title | Title | text | true | |
|
||||
|
||||
**f = > web.form table="notes" action="insert"**
|
||||
**f = > `f`.fields fields=`fields`**
|
||||
|
||||
**intro = "<div class=\"cols\"><section id=\"left\">voice</section><div id=\"qd-note-form-mount\"></div></div>"**
|
||||
**page = > web.page title="Slot" intro=`intro`**
|
||||
**page = > `page`.compose_form id="note" form=`f` target="#qd-note-form-mount"**
|
||||
|
||||
**tgt = > json.get value=`page` key="form_target"**
|
||||
1. `tgt`
|
||||
> print text=target-ok
|
||||
2. *
|
||||
> print text=target-fail
|
||||
|
||||
**html = > `page`.render**
|
||||
**`has_mount` = > text.contains text=`html` sub="qd-note-form-mount"**
|
||||
**`has_form` = > text.contains text=`html` sub="site-form"**
|
||||
**`order_ok` = > text.contains text=`html` sub="qd-note-form-mount\"><div class=\"site-form\""**
|
||||
1. `has_mount`
|
||||
1. `has_form`
|
||||
1. `order_ok`
|
||||
> print text=slot-ok
|
||||
2. *
|
||||
> print text=slot-order-fail
|
||||
2. *
|
||||
> print text=slot-form-fail
|
||||
2. *
|
||||
> print text=slot-mount-fail
|
||||
@@ -1,70 +0,0 @@
|
||||
---
|
||||
title: web form smoke
|
||||
description: Offline form fields / validate / submit (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import articles:web-fixtures/db/articles.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/form-smoke.db"**
|
||||
**schema = > articles.schema**
|
||||
> `store`.init name=articles fields=`schema`
|
||||
|
||||
`fields` =
|
||||
|
||||
| 字段 | 标签 | 类型 | 必填 | 默认 |
|
||||
|------|------|------|------|------|
|
||||
| title | Title | text | true | |
|
||||
| body | Body | textarea | false | |
|
||||
|
||||
`rules` =
|
||||
|
||||
| 字段 | 规则 | 消息 |
|
||||
|------|------|------|
|
||||
| title | required | Title is required |
|
||||
| title | max:120 | Title is too long |
|
||||
|
||||
**f = > web.form table="articles" action="insert"**
|
||||
**f = > `f`.fields fields=`fields`**
|
||||
**f = > `f`.rules rules=`rules`**
|
||||
|
||||
`bad` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| | hello |
|
||||
|
||||
**v = > `f`.validate data=`bad`**
|
||||
**ok = > json.get value=`v` key="ok"**
|
||||
1. `ok`
|
||||
> print text=validate-should-fail
|
||||
2. *
|
||||
> print text=validate-ok
|
||||
|
||||
`good` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| From form | Body via submit |
|
||||
|
||||
**sub = > `f`.submit data=`good` db=`store`**
|
||||
**sok = > json.get value=`sub` key="ok"**
|
||||
1. `sok`
|
||||
> print text=submit-ok
|
||||
2. *
|
||||
> print text=submit-fail
|
||||
|
||||
**rows = > `store`.select table="articles" limit=10**
|
||||
**n = > len value=`rows`**
|
||||
1. `n` >= 1
|
||||
> print text=db-ok
|
||||
2. *
|
||||
> print text=db-fail
|
||||
|
||||
**html = > `f`.render id="article"**
|
||||
1. `html`
|
||||
> print text=render-ok
|
||||
2. *
|
||||
> print text=render-fail
|
||||
@@ -1,123 +0,0 @@
|
||||
---
|
||||
title: web form source live server
|
||||
description: Request-context field sources — body only; author/slug stamped server-side.
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
`post_schema` =
|
||||
|
||||
| 字段 | 类型 | 必填 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| slug | text | true |
|
||||
| title | text | true |
|
||||
| content | text | true |
|
||||
|
||||
`comment_schema` =
|
||||
|
||||
| 字段 | 类型 | 必填 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| post_slug | text | true |
|
||||
| author | text | true |
|
||||
| body | text | true |
|
||||
| created_at | text | false |
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/form-source-live.db"**
|
||||
> `store`.init name=posts fields=`post_schema`
|
||||
> `store`.init name=comments fields=`comment_schema`
|
||||
> `store`.exec sql="DELETE FROM comments"
|
||||
> `store`.exec sql="DELETE FROM posts"
|
||||
|
||||
`seed` =
|
||||
|
||||
| slug | title | content |
|
||||
|------|-------|---------|
|
||||
| hello | Hello | Body of hello |
|
||||
|
||||
> `store`.insert table=posts rows=`seed`
|
||||
|
||||
`detail` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | posts.title | |
|
||||
| body | posts.content | |
|
||||
|
||||
`post_q` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| slug | = | {slug} |
|
||||
|
||||
`comment_fields` =
|
||||
|
||||
| 字段 | 标签 | 类型 | 必填 | 默认 | 来源 |
|
||||
|------|------|------|------|------|------|
|
||||
| body | Comment | textarea | true | | client |
|
||||
| author | | text | true | | session.username |
|
||||
| post_slug | | text | true | | route.slug |
|
||||
| created_at | | text | false | | now |
|
||||
|
||||
`comment_rules` =
|
||||
|
||||
| 字段 | 规则 | 消息 |
|
||||
|------|------|------|
|
||||
| body | required | body required |
|
||||
| author | required | login required |
|
||||
| post_slug | required | slug required |
|
||||
|
||||
**cf = > web.form table="comments" action="insert"**
|
||||
**cf = > `cf`.fields fields=`comment_fields`**
|
||||
**cf = > `cf`.rules rules=`comment_rules`**
|
||||
|
||||
`comment_cards` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | comments.author | |
|
||||
| body | comments.body | |
|
||||
| meta | comments.created_at | |
|
||||
|
||||
`comment_q` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| post_slug | = | {slug} |
|
||||
|
||||
**post = > web.page title="Post" intro="<section class='post-comments'><h2>Comments</h2><div id='comment-list'></div><div id='comment-form-mount'></div></section>"**
|
||||
**post = > `post`.compose_main main=`detail`**
|
||||
**post = > `post`.query query=`post_q`**
|
||||
**post = > `post`.detail detail=True**
|
||||
**post = > `post`.compose_list main=`comment_cards` query=`comment_q` order="-created_at" target="#comment-list"**
|
||||
**post = > `post`.compose_form form=`cf` id="comment" target="#comment-form-mount"**
|
||||
|
||||
`users` =
|
||||
|
||||
| 行 | 用户 | 密码 |
|
||||
|----|------|------|
|
||||
| 1 | alice | secret |
|
||||
|
||||
**app = > web.app page=`post` db=`store` port=18117**
|
||||
**app = > `app`.route path="/post/{slug}" page=`post`**
|
||||
**app = > `app`.auth users=`users` login_path="/login" login_redirect="/" session_ttl=3600**
|
||||
**app = > `app`.mount_form id="comment" form=`cf`**
|
||||
|
||||
`api` =
|
||||
|
||||
| 路径 | 方法 | 表 | 条件 | 排序 | 上限 |
|
||||
|------|------|----|------|------|------|
|
||||
| /api/comments | GET | comments | | "-created_at" | 50 |
|
||||
|
||||
**app = > `app`.configure json=`api`**
|
||||
> `app`.listen
|
||||
@@ -1,30 +0,0 @@
|
||||
---
|
||||
title: web G12 API key smoke (W-G12)
|
||||
description: Offline web_api_key_check via Go libweb.so.
|
||||
import plugin:lib/plugin.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = "../../plugins/web/build/libweb.so"**
|
||||
> plugin.load path=`p`
|
||||
|
||||
**pepper = "smoke-pepper"**
|
||||
|
||||
`keys` =
|
||||
|
||||
| hash | scopes |
|
||||
|------|--------|
|
||||
| 0ae9134cca7eff9d756fbf52402ee28ae0c2be22f01e53653e4fe86021479703 | read,api |
|
||||
|
||||
**ok = > web_api_key_check key="smoke-secret" authorization="" pepper=`pepper` keys=`keys`**
|
||||
1. [ok](ok)
|
||||
> print text=api-key-ok
|
||||
2. *
|
||||
> print text=api-key-fail
|
||||
|
||||
**bad = > web_api_key_check key="wrong" authorization="" pepper=`pepper` keys=`keys`**
|
||||
1. [ok](bad)
|
||||
> print text=api-key-bad-ok
|
||||
2. *
|
||||
> print text=api-key-bad-fail
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
title: web Go ABI smoke (W-G0)
|
||||
description: Load Go libweb.so; probe web_go_ready + web_page_new.
|
||||
import plugin:lib/plugin.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = "../../plugins/web/build/libweb.so"**
|
||||
> plugin.load path=`p`
|
||||
|
||||
**r = > web_go_ready**
|
||||
> print text=`r`
|
||||
|
||||
**page = > web_page_new title="Go Web" intro="W-G0" shell_css="" layout="" asset_version=""**
|
||||
> print text=`page`
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
title: web hosting live helpers
|
||||
description: Tiny lib used by hosting live-server invoke route (nested plugin call).
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
## echo
|
||||
+ `msg`=""
|
||||
+ `payload`=None
|
||||
|
||||
Nested plugin call (`web.page`) while `app.listen` is the outer plugin frame —
|
||||
must not clear GLOBAL_HOST so a second HTTP invoke still works.
|
||||
|
||||
**pg = > web.page title=`msg`**
|
||||
**title = [title](pg)**
|
||||
|
||||
`out` =
|
||||
|
||||
| ok | msg | title |
|
||||
|----|-----|-------|
|
||||
| true | `msg` | `title` |
|
||||
|
||||
*out*
|
||||
@@ -1,22 +0,0 @@
|
||||
---
|
||||
title: web hosting live server
|
||||
description: Listen with proxy (→ mock upstream) and invoke routes for gold.rs.
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import demo:web-hosting-helpers.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**pg = > web.page title="hosting-live"**
|
||||
**app = > web.app page=`pg` host=127.0.0.1 port=18141**
|
||||
**app = > `app`.proxy path="/proxy/sse" upstream="http://127.0.0.1:18142/sse" stream=True methods="POST"**
|
||||
**app = > `app`.invoke path="/api/echo" fn="demo.echo" method="POST" body="json"**
|
||||
> `app`.listen
|
||||
@@ -1,55 +0,0 @@
|
||||
---
|
||||
title: web compose_intro bind table
|
||||
description: Intro uses the same front/back/style bind as compose_main.
|
||||
import web:ext/web/web.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`intro` =
|
||||
|
||||
| front | back | style |
|
||||
|-------|------|-------|
|
||||
| kicker | Demo kicker | kicker |
|
||||
| title | Hello | intro_title |
|
||||
| lede | "Try code and [link](/x)." | lede |
|
||||
| claim | A | claim |
|
||||
| claim | B | claim |
|
||||
| step | First step | step |
|
||||
|
||||
**page = > web.page title="Intro bind"**
|
||||
**page = > page.compose_intro intro=intro**
|
||||
**html = > page.render**
|
||||
|
||||
**a = > split value=`html` sep="class=\"kicker\""**
|
||||
**na = > len value=`a`**
|
||||
**b = > split value=`html` sep="class=\"intro_title\""**
|
||||
**nb = > len value=`b`**
|
||||
**c = > split value=`html` sep="href=\"/x\""**
|
||||
**nc = > len value=`c`**
|
||||
**d = > split value=`html` sep="class=\"claim\""**
|
||||
**nd = > len value=`d`**
|
||||
**e = > split value=`html` sep="class=\"steps\""**
|
||||
**ne = > len value=`e`**
|
||||
1. `na` > 1
|
||||
1. `nb` > 1
|
||||
1. `nc` > 1
|
||||
1. `nd` > 1
|
||||
1. `ne` > 1
|
||||
> print text=compose-intro-ok
|
||||
2. *
|
||||
> print text=compose-intro-steps-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=compose-intro-claim-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=compose-intro-link-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=compose-intro-title-missing
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=compose-intro-kicker-missing
|
||||
> sys.exit code=1
|
||||
@@ -1,62 +0,0 @@
|
||||
---
|
||||
title: web middleware live server
|
||||
description: Offline-assembled app that listens with CORS/security/compress/body_limit/json.
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!-- load web plugin so ABI primitives are registered -->
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
`schema` =
|
||||
|
||||
| 字段 | 类型 |
|
||||
|------|------|
|
||||
| title | text |
|
||||
| body | text |
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/mw-live.db"**
|
||||
> `store`.init name=articles fields=`schema`
|
||||
> `store`.exec sql="DELETE FROM articles"
|
||||
|
||||
`rows` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Hello | first post |
|
||||
|
||||
> `store`.insert table=articles rows=`rows`
|
||||
|
||||
**pg = > web.page title="live"**
|
||||
**app = > web.app page=`pg` db=`store` port=18099**
|
||||
|
||||
`cors` =
|
||||
|
||||
| 允许来源 | 方法 | 头 | 暴露头 | 凭证 |
|
||||
|----------|------|----|--------|------|
|
||||
| https://a.example | GET,POST | Content-Type | X-Total | true |
|
||||
|
||||
`sec` =
|
||||
|
||||
| 头 | 值 |
|
||||
|----|----|
|
||||
| X-Frame-Options | DENY |
|
||||
| X-Content-Type-Options | nosniff |
|
||||
|
||||
`api` =
|
||||
|
||||
| 路径 | 方法 | 表 | 条件 | 排序 | 上限 |
|
||||
|------|------|----|----|----|------|
|
||||
| /api/posts | GET | articles | | | 10 |
|
||||
| /api/publish | POST | articles | | | 10 |
|
||||
|
||||
**app = > `app`.configure cors=`cors` security=`sec` compress=True body_limit=1000 json=`api`**
|
||||
> `app`.listen
|
||||
@@ -1,147 +0,0 @@
|
||||
---
|
||||
title: web middleware smoke
|
||||
description: Offline assemble of CORS/security/compress/json middleware (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!-- load web plugin so ABI primitives are registered -->
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
<!-- CORS table: |允许来源|方法|头|暴露头|凭证| -->
|
||||
|
||||
`cors` =
|
||||
|
||||
| 允许来源 | 方法 | 头 | 暴露头 | 凭证 |
|
||||
|----------|------|----|--------|------|
|
||||
| https://a.example | GET,POST | Content-Type,Authorization | X-Total | true |
|
||||
| https://b.example | GET | Content-Type | | |
|
||||
|
||||
<!-- security table: |头|值| -->
|
||||
|
||||
`sec` =
|
||||
|
||||
| 头 | 值 |
|
||||
|----|----|
|
||||
| X-Frame-Options | DENY |
|
||||
| X-Content-Type-Options | nosniff |
|
||||
| Content-Security-Policy | default-src 'self' |
|
||||
|
||||
<!-- json routes table: |路径|方法|表|条件|排序|上限| -->
|
||||
|
||||
`api` =
|
||||
|
||||
| 路径 | 方法 | 表 | 条件 | 排序 | 上限 |
|
||||
|------|------|----|----|----|------|
|
||||
| /api/posts | GET | articles | | "-created_at" | 20 |
|
||||
| /api/publish | POST | articles | | | 10 |
|
||||
|
||||
<!-- assemble via app.configure -->
|
||||
|
||||
**pg = > web.page title="mw"**
|
||||
**app = > web.app page=`pg`**
|
||||
**app = > `app`.configure cors=`cors` security=`sec` compress=True body_limit=1048576 json=`api`**
|
||||
|
||||
**mw = [middleware](app)**
|
||||
|
||||
<!-- cors -->
|
||||
|
||||
**cobj = [cors](mw)**
|
||||
**origins = [allow_origins](cobj)**
|
||||
**o0 = [1](origins)**
|
||||
1. `o0` == "https://a.example"
|
||||
> print text=cors-origin-ok
|
||||
2. *
|
||||
> print text=cors-origin-fail
|
||||
|
||||
**methods = [methods](cobj)**
|
||||
**m1 = [2](methods)**
|
||||
1. `m1` == "POST"
|
||||
> print text=cors-method-ok
|
||||
2. *
|
||||
> print text=cors-method-fail
|
||||
|
||||
**expose = [expose_headers](cobj)**
|
||||
**e0 = [1](expose)**
|
||||
1. `e0` == "X-Total"
|
||||
> print text=cors-expose-ok
|
||||
2. *
|
||||
> print text=cors-expose-fail
|
||||
|
||||
**cred = [credentials](cobj)**
|
||||
1. `cred`
|
||||
> print text=cors-cred-ok
|
||||
2. *
|
||||
> print text=cors-cred-fail
|
||||
|
||||
<!-- security -->
|
||||
|
||||
**secmap = [security](mw)**
|
||||
**frame = [X-Frame-Options](secmap)**
|
||||
1. `frame` == "DENY"
|
||||
> print text=security-frame-ok
|
||||
2. *
|
||||
> print text=security-frame-fail
|
||||
|
||||
**csp = [Content-Security-Policy](secmap)**
|
||||
1. `csp` == "default-src 'self'"
|
||||
> print text=security-csp-ok
|
||||
2. *
|
||||
> print text=security-csp-fail
|
||||
|
||||
<!-- compress / body_limit -->
|
||||
|
||||
**comp = [compress](mw)**
|
||||
1. `comp`
|
||||
> print text=compress-ok
|
||||
2. *
|
||||
> print text=compress-fail
|
||||
|
||||
**bl = [body_limit](mw)**
|
||||
1. `bl` == 1048576
|
||||
> print text=body-limit-ok
|
||||
2. *
|
||||
> print text=body-limit-fail
|
||||
|
||||
<!-- json routes -->
|
||||
|
||||
**jmap = [json_routes](mw)**
|
||||
**posts = [api/posts](jmap)**
|
||||
**pok = [method](posts)**
|
||||
1. `pok` == "GET"
|
||||
> print text=json-get-ok
|
||||
2. *
|
||||
> print text=json-get-fail
|
||||
|
||||
**ptable = [table](posts)**
|
||||
1. `ptable` == "articles"
|
||||
> print text=json-table-ok
|
||||
2. *
|
||||
> print text=json-table-fail
|
||||
|
||||
**porder = [order](posts)**
|
||||
1. `porder` == "-created_at"
|
||||
> print text=json-order-ok
|
||||
2. *
|
||||
> print text=json-order-fail
|
||||
|
||||
**plimit = [limit](posts)**
|
||||
1. `plimit` == 20
|
||||
> print text=json-limit-ok
|
||||
2. *
|
||||
> print text=json-limit-fail
|
||||
|
||||
**pub = [api/publish](jmap)**
|
||||
**pmethod = [method](pub)**
|
||||
1. `pmethod` == "POST"
|
||||
> print text=json-post-ok
|
||||
2. *
|
||||
> print text=json-post-fail
|
||||
@@ -1,148 +0,0 @@
|
||||
---
|
||||
title: web network-extension smoke
|
||||
description: Session/auth/ws ABI primitives (offline).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!-- load web plugin so ABI primitives are registered -->
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
<!-- admin users table (row-oriented records) -->
|
||||
|
||||
`users` =
|
||||
|
||||
| 行 | 用户 | 密码 |
|
||||
|----|------|------|
|
||||
| 1 | admin | secret |
|
||||
| 2 | 站长 | pw123 |
|
||||
|
||||
<!-- session CRUD -->
|
||||
|
||||
**sess = > web_session_new ttl_sec=120**
|
||||
**sid = [id](sess)**
|
||||
1. `sid` != ""
|
||||
> print text=session-new-ok
|
||||
2. *
|
||||
> print text=session-new-fail
|
||||
|
||||
**set1 = > web_session_set id=`sid` key="theme" value="dark"**
|
||||
**ok1 = [ok](set1)**
|
||||
1. `ok1`
|
||||
> print text=session-set-ok
|
||||
2. *
|
||||
> print text=session-set-fail
|
||||
|
||||
**get1 = > web_session_get id=`sid` key="theme"**
|
||||
**v1 = [value](get1)**
|
||||
1. `v1` == "dark"
|
||||
> print text=session-get-ok
|
||||
2. *
|
||||
> print text=session-get-fail
|
||||
|
||||
**del1 = > web_session_del id=`sid` key="theme"**
|
||||
**ok2 = [ok](del1)**
|
||||
1. `ok2`
|
||||
> print text=session-del-ok
|
||||
2. *
|
||||
> print text=session-del-fail
|
||||
|
||||
**get2 = > web_session_get id=`sid` key="theme"**
|
||||
**ok3 = [ok](get2)**
|
||||
1. `ok3`
|
||||
> print text=session-del-confirm-fail
|
||||
2. *
|
||||
> print text=session-del-confirm
|
||||
|
||||
<!-- auth login/check/logout -->
|
||||
|
||||
**login = > web_auth_login username="admin" password="secret" users=`users` session_ttl=120**
|
||||
**lok = [ok](login)**
|
||||
1. `lok`
|
||||
> print text=auth-login-ok
|
||||
2. *
|
||||
> print text=auth-login-fail
|
||||
|
||||
**sid2 = [session_id](login)**
|
||||
**check = > web_auth_check session_id=`sid2`**
|
||||
**cok = [ok](check)**
|
||||
1. `cok`
|
||||
> print text=auth-check-ok
|
||||
2. *
|
||||
> print text=auth-check-fail
|
||||
|
||||
**badlogin = > web_auth_login username="admin" password="wrong" users=`users` session_ttl=120**
|
||||
**bok = [ok](badlogin)**
|
||||
1. `bok`
|
||||
> print text=auth-bad-should-fail
|
||||
2. *
|
||||
> print text=auth-bad-ok
|
||||
|
||||
**zhlogin = > web_auth_login username="站长" password="pw123" users=`users` session_ttl=120**
|
||||
**zhok = [ok](zhlogin)**
|
||||
1. `zhok`
|
||||
> print text=auth-zh-ok
|
||||
2. *
|
||||
> print text=auth-zh-fail
|
||||
|
||||
**logout = > web_auth_logout session_id=`sid2`**
|
||||
**dok = [ok](logout)**
|
||||
1. `dok`
|
||||
> print text=auth-logout-ok
|
||||
2. *
|
||||
> print text=auth-logout-fail
|
||||
|
||||
**check2 = > web_auth_check session_id=`sid2`**
|
||||
**cok2 = [ok](check2)**
|
||||
1. `cok2`
|
||||
> print text=auth-logout-confirm-fail
|
||||
2. *
|
||||
> print text=auth-logout-confirm
|
||||
|
||||
<!-- route ws + app auth (offline) -->
|
||||
|
||||
**pg = > web.page title="ws-test"**
|
||||
**app = > web.app page=`pg` admin=True**
|
||||
**app = > `app`.route_ws path="/live" echo=True**
|
||||
**routes = [ws_routes](app)**
|
||||
**has_live = [/live](routes)**
|
||||
1. `has_live`
|
||||
> print text=ws-route-ok
|
||||
2. *
|
||||
> print text=ws-route-fail
|
||||
|
||||
**app = > `app`.auth users=`users` session_ttl=120**
|
||||
**authobj = [auth](app)**
|
||||
**ausers = [users](authobj)**
|
||||
**au1 = [用户]([1](ausers))**
|
||||
**ou1 = [用户]([1](users))**
|
||||
1. `au1` == `ou1`
|
||||
> print text=app-auth-ok
|
||||
2. *
|
||||
> print text=app-auth-fail
|
||||
|
||||
<!-- via ext/web author surface -->
|
||||
|
||||
**authz = > web.auth users=`users` session_ttl=120**
|
||||
**login2 = > `authz`.login username="admin" password="secret"**
|
||||
**lok2 = [ok](login2)**
|
||||
1. `lok2`
|
||||
> print text=ext-auth-ok
|
||||
2. *
|
||||
> print text=ext-auth-fail
|
||||
|
||||
**ws = > web.ws timeout_sec=1**
|
||||
**badurl = > `ws`.connect url="ws://127.0.0.1:1" message="hi"**
|
||||
**bwok = [ok](badurl)**
|
||||
1. `bwok`
|
||||
> print text=ws-connect-should-fail
|
||||
2. *
|
||||
> print text=ws-connect-error-ok
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
title: web P3 live — gallery HTML + download ETag
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**blob = > web.storage url="file:web-fixtures/data/p3-live-blobs"**
|
||||
> `blob`.put key="uploads/hello.txt" body="etag-body" content_type="text/plain"
|
||||
|
||||
**pg = > web.page title="p3-live"**
|
||||
**app = > web.app page=`pg` port=18131**
|
||||
**app = > `app`.download path="/_media/{*key}" storage=`blob` disposition="inline"**
|
||||
**app = > `app`.gallery path="/gallery" storage=`blob` prefix="uploads/" title="P3 Gallery" download_base="/_media"**
|
||||
> `app`.listen
|
||||
@@ -1,107 +0,0 @@
|
||||
---
|
||||
title: web P3 smoke — audit timestamps, FK, RBAC, gallery (offline)
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/p3-smoke.db"**
|
||||
> `store`.exec sql="DROP TABLE IF EXISTS comments"
|
||||
> `store`.exec sql="DROP TABLE IF EXISTS posts"
|
||||
|
||||
`post_fields` =
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| id | int | 否 |
|
||||
| title | text | 否 |
|
||||
| created_at | timestamp | 是 |
|
||||
| updated_at | timestamp | 是 |
|
||||
|
||||
> `store`.init name="posts" fields=`post_fields`
|
||||
|
||||
`comment_fields` =
|
||||
|
||||
| 字段 | 类型 | 可空 | 外键 |
|
||||
|------|------|------|------|
|
||||
| id | int | 否 | |
|
||||
| post_id | int | 否 | posts |
|
||||
| body | text | 否 | |
|
||||
|
||||
> `store`.init name="comments" fields=`comment_fields`
|
||||
|
||||
`rows` =
|
||||
|
||||
| @ | title |
|
||||
|---|-------|
|
||||
| 1 | Hello P3 |
|
||||
|
||||
> `store`.insert table="posts" rows=`rows`
|
||||
|
||||
**got = > `store`.get table="posts" id=1**
|
||||
**ca = [created_at](got)**
|
||||
1. `ca`
|
||||
> print text=audit-insert-ok
|
||||
2. *
|
||||
> print text=audit-insert-fail
|
||||
|
||||
**upd = > json.parse text={"title":"Hello P3b"}**
|
||||
> `store`.update table="posts" id=1 row=`upd`
|
||||
**got2 = > `store`.get table="posts" id=1**
|
||||
**ua2 = [updated_at](got2)**
|
||||
1. `ua2`
|
||||
> print text=audit-update-ok
|
||||
2. *
|
||||
> print text=audit-update-fail
|
||||
|
||||
**fk = > `store`.query sql="SELECT sql FROM sqlite_master WHERE type='table' AND name='comments'"**
|
||||
**fkddl = [sql]([1]([rows](fk)))**
|
||||
1. `fkddl`
|
||||
> print text=fk-ok
|
||||
2. *
|
||||
> print text=fk-fail
|
||||
|
||||
`users` =
|
||||
|
||||
| username | password | role |
|
||||
|----------|----------|------|
|
||||
| admin | secret | admin |
|
||||
| alice | secret | author |
|
||||
|
||||
**login = > web_auth_login username="alice" password="secret" users=`users` session_ttl=120**
|
||||
**role = [role](login)**
|
||||
1. `role` == "author"
|
||||
> print text=rbac-login-ok
|
||||
2. *
|
||||
> print text=rbac-login-fail
|
||||
|
||||
**pg = > web.page title="p3"**
|
||||
**app = > web.app page=`pg` port=18130**
|
||||
**app = > `app`.auth users=`users`**
|
||||
**app = > `app`.gate path="/write*" roles="admin,author"**
|
||||
**gates = [gates](app)**
|
||||
**ng = > len value=`gates`**
|
||||
**gpath = [path]([1](gates))**
|
||||
1. `ng` == 1 and `gpath` == "/write*"
|
||||
> print text=rbac-gate-ok
|
||||
2. *
|
||||
> print text=rbac-gate-fail
|
||||
|
||||
**blob = > web.storage url="file:web-fixtures/data/p3-gallery"**
|
||||
> `blob`.put key="uploads/a.txt" body="hi" content_type="text/plain"
|
||||
**app = > `app`.gallery path="/gallery" storage=`blob` prefix="uploads/" title="Media" download_base="/_media"**
|
||||
**gal = [gallery_routes](app)**
|
||||
**g = [/gallery](gal)**
|
||||
1. `g`
|
||||
> print text=gallery-ok
|
||||
2. *
|
||||
> print text=gallery-fail
|
||||
@@ -1,52 +0,0 @@
|
||||
---
|
||||
title: web part smoke
|
||||
description: Routed pages stamp _route and emit {path}/_part/{id} slot sources.
|
||||
import web:ext/web/web.mq.md
|
||||
import nav:web-fixtures/components/nav.mq.md
|
||||
import side:web-fixtures/components/side.mq.md
|
||||
import foot:web-fixtures/components/foot.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`layout` =
|
||||
|
||||
| 组件 | 样式 |
|
||||
|------|------|
|
||||
| nav.`nav` | |
|
||||
| side.`side` | |
|
||||
| foot.`foot` | |
|
||||
|
||||
**home = > web.page title="Home" intro="<h1>Home</h1>"**
|
||||
**home = > `home`.compose_components components=`layout`**
|
||||
|
||||
**about = > web.page title="About" intro="<h1>About</h1>"**
|
||||
**about = > `about`.compose_components components=`layout`**
|
||||
|
||||
**app = > web.app page=`home` host=127.0.0.1 port=18081**
|
||||
**app = > `app`.route path="/about" page=`about`**
|
||||
|
||||
**routes = > json.get value=`app` key="routes"**
|
||||
**routed = > json.get value=`routes` key="/about"**
|
||||
**route = > json.get value=`routed` key="_route"**
|
||||
1. `route` == "/about"
|
||||
> print text=route-stamp-ok
|
||||
2. *
|
||||
> print text=route-stamp-fail
|
||||
|
||||
**home_html = > `home`.render**
|
||||
**home_chunks = > split value=`home_html` sep="/_part/"**
|
||||
**hn = > len value=`home_chunks`**
|
||||
1. `hn` >= 2
|
||||
> print text=home-part-ok
|
||||
2. *
|
||||
> print text=home-part-fail
|
||||
|
||||
**about_html = > `routed`.render**
|
||||
**about_chunks = > split value=`about_html` sep="/about/_part/"**
|
||||
**an = > len value=`about_chunks`**
|
||||
1. `an` >= 2
|
||||
> print text=route-part-ok
|
||||
2. *
|
||||
> print text=route-part-fail
|
||||
@@ -1,75 +0,0 @@
|
||||
---
|
||||
title: web proxy/invoke smoke
|
||||
description: Offline assemble of app.proxy and app.invoke routes (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
`proxy_tbl` =
|
||||
|
||||
| path | upstream | stream | strip_prefix | methods | headers_from_env | timeout_ms |
|
||||
|------|----------|--------|--------------|---------|------------------|------------|
|
||||
| /proxy/chat | $OPENAI_BASE_URL | True | /proxy | POST | OPENAI_API_KEY=Authorization | 60000 |
|
||||
|
||||
`invoke_tbl` =
|
||||
|
||||
| path | method | fn | body | return |
|
||||
|------|--------|-----|------|--------|
|
||||
| /api/echo | POST | demo.echo | json | json |
|
||||
|
||||
**pg = > web.page title="proxy-invoke"**
|
||||
**app = > web.app page=`pg`**
|
||||
**app = > `app`.configure proxy=`proxy_tbl` invoke=`invoke_tbl`**
|
||||
**app = > `app`.proxy path="/v1/stream" upstream="https://example.com/v1/chat" stream=True headers_from_env="TOKEN=X-Token"**
|
||||
**app = > `app`.invoke path="/api/ping" fn="demo.ping" method="GET" body="query"**
|
||||
|
||||
**proutes = [proxy_routes](app)**
|
||||
**chat = [proxy/chat](proutes)**
|
||||
**up = [upstream](chat)**
|
||||
1. `up` == "$OPENAI_BASE_URL"
|
||||
> print text=proxy-table-ok
|
||||
2. *
|
||||
> print text=proxy-table-fail
|
||||
|
||||
**stream = [stream](chat)**
|
||||
1. `stream`
|
||||
> print text=proxy-stream-ok
|
||||
2. *
|
||||
> print text=proxy-stream-fail
|
||||
|
||||
**hdr = [headers_from_env](chat)**
|
||||
1. `hdr` == "OPENAI_API_KEY=Authorization"
|
||||
> print text=proxy-env-ok
|
||||
2. *
|
||||
> print text=proxy-env-fail
|
||||
|
||||
**v1 = [v1/stream](proutes)**
|
||||
**v1u = [upstream](v1)**
|
||||
1. `v1u` == "https://example.com/v1/chat"
|
||||
> print text=proxy-method-ok
|
||||
2. *
|
||||
> print text=proxy-method-fail
|
||||
|
||||
**iroutes = [invoke_routes](app)**
|
||||
**echo = [api/echo](iroutes)**
|
||||
**efn = [fn](echo)**
|
||||
1. `efn` == "demo.echo"
|
||||
> print text=invoke-table-ok
|
||||
2. *
|
||||
> print text=invoke-table-fail
|
||||
|
||||
**ping = [api/ping](iroutes)**
|
||||
**pm = [method](ping)**
|
||||
1. `pm` == "GET"
|
||||
> print text=invoke-method-ok
|
||||
2. *
|
||||
> print text=invoke-method-fail
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: ext/security rbac smoke
|
||||
import rbac:ext/security/rbac.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**gate = > rbac.rbac**
|
||||
**r = > `gate`.can permissions="desk:access,posts:read" needed="desk:access"**
|
||||
**ok = [ok](r)**
|
||||
**allowed = [allowed](r)**
|
||||
1. `ok`
|
||||
1. `allowed`
|
||||
> print text=rbac-ok
|
||||
2. *
|
||||
> print text=rbac-fail
|
||||
2. *
|
||||
> print text=rbac-fail
|
||||
@@ -1,56 +0,0 @@
|
||||
---
|
||||
title: web RBAC smoke
|
||||
description: app.rbac flag + gate permissions CSV stored on app bag
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
> print text=rbac-smoke-start
|
||||
|
||||
**首页 = > web.page title="home"**
|
||||
`用户表` =
|
||||
| 用户名 | 密码 | 角色 |
|
||||
|--------|------|------|
|
||||
| admin | secret | admin |
|
||||
|
||||
**应用 = > web.app page=`首页` admin=False**
|
||||
**应用 = > `应用`.enable_rbac**
|
||||
**authbag = > json.get value=`应用` key="auth"**
|
||||
**rbac_on = > json.get value=`authbag` key="rbac"**
|
||||
1. `rbac_on` == True
|
||||
> print text=rbac-flag-ok
|
||||
2. *
|
||||
> print text=rbac-flag-fail
|
||||
|
||||
**应用 = > `应用`.auth users=`用户表` login_path="/login"**
|
||||
**authbag2 = > json.get value=`应用` key="auth"**
|
||||
**rbac_kept = > json.get value=`authbag2` key="rbac"**
|
||||
1. `rbac_kept` == True
|
||||
> print text=rbac-survives-auth-ok
|
||||
2. *
|
||||
> print text=rbac-survives-auth-fail
|
||||
|
||||
**应用 = > `应用`.gate path="/desk" permissions="desk:access" match="prefix" on_deny="redirect" exclude="/login"**
|
||||
**gates = > json.get value=`应用` key="gates"**
|
||||
**g1 = > at value=`gates` index=1**
|
||||
**perms = > json.get value=`g1` key="permissions"**
|
||||
**p0 = > at value=`perms` index=0**
|
||||
1. `p0` == "desk:access"
|
||||
> print text=gate-perm-ok
|
||||
2. *
|
||||
> print text=gate-perm-fail
|
||||
|
||||
**应用2 = > web.app page=`首页` admin=False**
|
||||
**应用2 = > `应用2`.gate path="/desk/roles" permissions="roles:manage" roles="editor" match="exact"**
|
||||
**gates2 = > json.get value=`应用2` key="gates"**
|
||||
**g0 = > at value=`gates2` index=0**
|
||||
**perms2 = > json.get value=`g0` key="permissions"**
|
||||
**p1 = > at value=`perms2` index=0**
|
||||
1. `p1` == "roles:manage"
|
||||
> print text=gate-roles-manage-ok
|
||||
2. *
|
||||
> print text=gate-roles-manage-fail
|
||||
|
||||
> print text=rbac-smoke-done
|
||||
@@ -1,49 +0,0 @@
|
||||
---
|
||||
title: web RBAC db register/assign smoke
|
||||
description: EnsureSchema path via create_role + assign + can
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
> print text=rbac-db-start
|
||||
|
||||
**db = > web.db url="sqlite::memory:"**
|
||||
**url = > json.get value=`db` key="url"**
|
||||
**rbac = > web.rbac**
|
||||
|
||||
**seed = > `rbac`.create_role url=`db` name="reviewer"**
|
||||
**ok1 = > json.get value=`seed` key="ok"**
|
||||
1. `ok1` == True
|
||||
> print text=create-role-ok
|
||||
2. *
|
||||
> print text=create-role-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**setp = > `rbac`.set_role_permissions url=`db` role="reviewer" permissions="comments:create,desk:access"**
|
||||
**ok2 = > json.get value=`setp` key="ok"**
|
||||
1. `ok2` == True
|
||||
> print text=set-perms-ok
|
||||
2. *
|
||||
> print text=set-perms-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**can = > `rbac`.can permissions="comments:create,desk:access" needed="desk:access"**
|
||||
**allowed = > json.get value=`can` key="allowed"**
|
||||
1. `allowed` == True
|
||||
> print text=can-ok
|
||||
2. *
|
||||
> print text=can-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**deny = > `rbac`.can permissions="comments:create" needed="roles:manage"**
|
||||
**denied = > json.get value=`deny` key="allowed"**
|
||||
1. `denied` == False
|
||||
> print text=can-deny-ok
|
||||
2. *
|
||||
> print text=can-deny-fail
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=rbac-db-done
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
title: web route smoke
|
||||
description: Offline app.route registration (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**home = > web.page title="Home" intro="<h1>Home</h1>"**
|
||||
**about = > web.page title="About" intro="<h1>About</h1>"**
|
||||
**app = > web.app page=`home` host=127.0.0.1 port=18081**
|
||||
**app = > `app`.route path="/about" page=`about`**
|
||||
**app = > `app`.route path="docs" page=`about`**
|
||||
|
||||
**routes = > json.get value=`app` key="routes"**
|
||||
**about_page = > json.get value=`routes` key="/about"**
|
||||
**docs_page = > json.get value=`routes` key="/docs"**
|
||||
|
||||
1. `about_page`
|
||||
> print text=about-ok
|
||||
2. *
|
||||
> print text=about-fail
|
||||
|
||||
1. `docs_page`
|
||||
> print text=docs-ok
|
||||
2. *
|
||||
> print text=docs-fail
|
||||
|
||||
**html = > `about`.render**
|
||||
1. `html`
|
||||
> print text=render-ok
|
||||
2. *
|
||||
> print text=render-fail
|
||||
@@ -1,48 +0,0 @@
|
||||
---
|
||||
title: web security smoke (W3)
|
||||
description: Password hash ABI + legacy plaintext login (offline).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!-- load web plugin -->
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
<!-- argon2 hash must be non-empty PHC string -->
|
||||
|
||||
**hash = > web_password_hash password="secret"**
|
||||
**h = [hash](hash)**
|
||||
1. `h` != ""
|
||||
> print text=hash-ok
|
||||
2. *
|
||||
> print text=hash-fail
|
||||
|
||||
<!-- legacy plaintext login still works for dev/gold -->
|
||||
|
||||
`users` =
|
||||
|
||||
| 行 | 用户 | 密码 |
|
||||
|----|------|------|
|
||||
| 1 | admin | secret |
|
||||
|
||||
**login = > web_auth_login username="admin" password="secret" users=`users` session_ttl=120**
|
||||
**lok = [ok](login)**
|
||||
1. `lok`
|
||||
> print text=auth-login-ok
|
||||
2. *
|
||||
> print text=auth-login-fail
|
||||
|
||||
**bad = > web_auth_login username="admin" password="wrong" users=`users` session_ttl=120**
|
||||
**bok = [ok](bad)**
|
||||
1. `bok`
|
||||
> print text=auth-bad-should-fail
|
||||
2. *
|
||||
> print text=auth-bad-reject-ok
|
||||
@@ -1,57 +0,0 @@
|
||||
---
|
||||
title: web db.select where smoke
|
||||
description: Offline select with map and filter-table where (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import articles:web-fixtures/db/articles.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/select-smoke.db"**
|
||||
**schema = > articles.schema**
|
||||
> `store`.init name=articles fields=`schema`
|
||||
> `store`.exec sql="DELETE FROM articles"
|
||||
|
||||
`rows` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Alpha | first |
|
||||
| Beta | second |
|
||||
| Alpha again | third |
|
||||
|
||||
> `store`.insert table=articles rows=`rows`
|
||||
|
||||
`eq` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Alpha | first |
|
||||
|
||||
**hit = > `store`.select table="articles" where=`eq` limit=50**
|
||||
**n = > len value=`hit`**
|
||||
1. `n` == 1
|
||||
> print text=map-where-ok
|
||||
2. *
|
||||
> print text=map-where-fail
|
||||
|
||||
`filt` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| title | like | %Alpha% |
|
||||
|
||||
**like_rows = > `store`.select table="articles" where=`filt` limit=50**
|
||||
**ln = > len value=`like_rows`**
|
||||
1. `ln` == 2
|
||||
> print text=like-ok
|
||||
2. *
|
||||
> print text=like-fail
|
||||
|
||||
**all = > `store`.select table="articles" limit=50**
|
||||
**an = > len value=`all`**
|
||||
1. `an` == 3
|
||||
> print text=all-ok
|
||||
2. *
|
||||
> print text=all-fail
|
||||
@@ -1,81 +0,0 @@
|
||||
---
|
||||
title: web assemble smoke
|
||||
description: Offline assemble + render markers (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import shell:web-fixtures/styles/shell.mq.md
|
||||
import nav:web-fixtures/components/nav.mq.md
|
||||
import side:web-fixtures/components/side.mq.md
|
||||
import foot:web-fixtures/components/foot.mq.md
|
||||
import articles:web-fixtures/db/articles.mq.md
|
||||
import fs:lib/fs.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/smoke.db"**
|
||||
**fields = > articles.schema**
|
||||
> `store`.init name=articles fields=`fields`
|
||||
**rows = > `store`.select table="articles" limit=1**
|
||||
1. `rows`
|
||||
**_ = 1**
|
||||
2. *
|
||||
**seed = > articles.seed**
|
||||
> `store`.insert table=articles rows=`seed`
|
||||
|
||||
`home` =
|
||||
|
||||
| 组件 | 样式 |
|
||||
|------|------|
|
||||
| nav.`nav` | shell.`topnav` |
|
||||
| side.`side` | shell.`side_panel` |
|
||||
| foot.`foot` | |
|
||||
|
||||
`index` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | articles.`articles`.title | shell.`card_title` |
|
||||
| body | articles.`articles`.body | shell.`card_body` |
|
||||
|
||||
**page = > web.page title="smoke" intro="<h1>smoke</h1>"**
|
||||
**page = > `page`.compose_components components=`home`**
|
||||
**page = > `page`.compose_main main=`index`**
|
||||
**html = > `page`.render db=`store`**
|
||||
|
||||
1. `html`
|
||||
> print text=render-ok
|
||||
2. *
|
||||
> print text=render-fail
|
||||
|
||||
**nav = > json.get value=`page` key="nav"**
|
||||
1. `nav`
|
||||
> print text=compose-nav-ok
|
||||
2. *
|
||||
> print text=compose-nav-fail
|
||||
|
||||
**side = > json.get value=`page` key="sidebar"**
|
||||
1. `side`
|
||||
> print text=compose-side-ok
|
||||
2. *
|
||||
> print text=compose-side-fail
|
||||
|
||||
**css = > json.get value=`page` key="styles_css"**
|
||||
1. `css`
|
||||
> print text=styles-ok
|
||||
2. *
|
||||
> print text=styles-fail
|
||||
|
||||
**parts = > json.get value=`page` key="parts"**
|
||||
**index_part = > json.get value=`parts` key="index"**
|
||||
1. `index_part`
|
||||
> print text=compose-ok
|
||||
2. *
|
||||
> print text=compose-fail
|
||||
|
||||
**got = > `store`.get table="articles" id=1**
|
||||
**title = > json.get value=`got` key="title"**
|
||||
1. `title` == "Hello Marqdo"
|
||||
> print text=db-ok
|
||||
2. *
|
||||
> print text=db-fail
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
title: browser spa helpers smoke
|
||||
description: store_set / spa_goto effect bags
|
||||
import browser:lib/browser.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**set = > browser.store_set key="k" value="v" scope="memory"**
|
||||
**op = > json.get value=`set` key="storage"**
|
||||
**op_name = > json.get value=`op` key="op"**
|
||||
**scope = > json.get value=`op` key="scope"**
|
||||
1. `op_name` == "set"
|
||||
1. `scope` == "memory"
|
||||
> print text=store-set-ok
|
||||
2. *
|
||||
> print text=scope-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=op-fail
|
||||
> sys.exit code=1
|
||||
|
||||
**nav = > browser.spa_goto url="/item" replace=False**
|
||||
**n = > json.get value=`nav` key="navigate"**
|
||||
**url = > json.get value=`n` key="url"**
|
||||
1. `url` == "/item"
|
||||
> print text=spa-goto-ok
|
||||
2. *
|
||||
> print text=spa-goto-fail
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=spa-helpers-ok
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: web static artifact smoke
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**pg = > web.page title="static"**
|
||||
**app = > web.app page=`pg`**
|
||||
**app = > `app`.static dir="web-fixtures/public" mount="/static"**
|
||||
**d = [static_dir](app)**
|
||||
**m = [static_mount](app)**
|
||||
1. `d`
|
||||
> print text=dir-ok
|
||||
2. *
|
||||
> print text=dir-fail
|
||||
1. `m` == "/static"
|
||||
> print text=mount-ok
|
||||
2. *
|
||||
> print text=mount-fail
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
title: web static smoke
|
||||
description: Offline app.static registration (no listen).
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**home = > web.page title="Home"**
|
||||
**app = > web.app page=`home` host=127.0.0.1 port=18081**
|
||||
**app = > `app`.static dir="web-fixtures/public" mount="/static"**
|
||||
|
||||
**dir = > json.get value=`app` key="static_dir"**
|
||||
1. `dir` == "web-fixtures/public"
|
||||
> print text=dir-ok
|
||||
2. *
|
||||
> print text=dir-fail
|
||||
|
||||
**mount = > json.get value=`app` key="static_mount"**
|
||||
1. `mount` == "/static"
|
||||
> print text=mount-ok
|
||||
2. *
|
||||
> print text=mount-fail
|
||||
|
||||
**app2 = > `app`.static dir="assets" mount="/assets"**
|
||||
**m2 = > json.get value=`app2` key="static_mount"**
|
||||
1. `m2` == "/assets"
|
||||
> print text=custom-ok
|
||||
2. *
|
||||
> print text=custom-fail
|
||||
@@ -1,30 +0,0 @@
|
||||
---
|
||||
title: web tenant bag smoke
|
||||
description: app.tenant mode=path stores config
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**首页 = > web.page title="t"**
|
||||
**应用 = > web.app page=`首页` admin=False**
|
||||
**应用 = > `应用`.tenant mode="path" param="t" column="tenant_id" default_scope=True**
|
||||
**bag = > json.get value=`应用` key="tenant"**
|
||||
**mode = > json.get value=`bag` key="mode"**
|
||||
**param = > json.get value=`bag` key="param"**
|
||||
**scope = > json.get value=`bag` key="default_scope"**
|
||||
1. `mode` == "path"
|
||||
1. `param` == "t"
|
||||
1. `scope` == True
|
||||
> print text=tenant-bag-ok
|
||||
2. *
|
||||
> print text=scope-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=param-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=mode-fail
|
||||
> sys.exit code=1
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
title: web upload live server (W5)
|
||||
description: Listen with upload + download routes for curl gold.
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**blob = > web.storage url="file:tests/ext/web-fixtures/data/upload-live-blobs"**
|
||||
|
||||
`types` =
|
||||
|
||||
| 类型 | 扩展名 |
|
||||
|------|--------|
|
||||
| text/plain | txt |
|
||||
| image/png | png |
|
||||
|
||||
**pg = > web.page title="upload-live"**
|
||||
**app = > web.app page=`pg` port=18101**
|
||||
**app = > `app`.configure body_limit=1048576**
|
||||
**app = > `app`.upload path="/_upload" field="file" storage=`blob` prefix="live/" max_bytes=1024 types=`types`**
|
||||
**app = > `app`.download path="/_media/{*key}" storage=`blob` disposition="attachment"**
|
||||
> `app`.listen
|
||||
@@ -1,77 +0,0 @@
|
||||
---
|
||||
title: web upload smoke (W5)
|
||||
description: Offline validate + save into file: storage.
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
`types` =
|
||||
|
||||
| 类型 | 扩展名 |
|
||||
|------|--------|
|
||||
| image/png | png |
|
||||
| text/plain | txt |
|
||||
|
||||
**m = > web.media**
|
||||
**ok = > `m`.validate filename="a.png" content_type="image/png" size=100 max_bytes=1000 types=`types`**
|
||||
**ook = [ok](ok)**
|
||||
1. `ook`
|
||||
> print text=validate-ok
|
||||
2. *
|
||||
> print text=validate-fail
|
||||
|
||||
**bad = > `m`.validate filename="a.exe" content_type="application/octet-stream" size=100 max_bytes=1000 types=`types`**
|
||||
**bok = [ok](bad)**
|
||||
1. `bok`
|
||||
> print text=reject-type-fail
|
||||
2. *
|
||||
> print text=reject-type-ok
|
||||
|
||||
**big = > `m`.validate filename="a.png" content_type="image/png" size=9000 max_bytes=1000 types=`types`**
|
||||
**gok = [ok](big)**
|
||||
1. `gok`
|
||||
> print text=reject-size-fail
|
||||
2. *
|
||||
> print text=reject-size-ok
|
||||
|
||||
**blob = > web.storage url="file:tests/ext/web-fixtures/data/upload-blobs"**
|
||||
**m = > web.media storage=`blob`**
|
||||
**saved = > `m`.save path="tests/ext/web-fixtures/upload/sample.txt" content_type="text/plain" prefix="smoke/"**
|
||||
**sok = [ok](saved)**
|
||||
**skey = [key](saved)**
|
||||
1. `sok`
|
||||
> print text=save-ok
|
||||
2. *
|
||||
> print text=save-fail
|
||||
|
||||
**got = > `blob`.get key=`skey`**
|
||||
**body = [body](got)**
|
||||
1. `body` == "hello-upload"
|
||||
> print text=save-roundtrip-ok
|
||||
2. *
|
||||
> print text=save-roundtrip-fail
|
||||
|
||||
<!-- form file field renders with multipart enctype -->
|
||||
|
||||
`fields` =
|
||||
|
||||
| name | label | type |
|
||||
|------|-------|------|
|
||||
| title | Title | text |
|
||||
| file | File | file |
|
||||
|
||||
**frm = > web.form table="x" fields=`fields`**
|
||||
**html = > `frm`.render id="up"**
|
||||
1. `html`
|
||||
> print text=form-file-ok
|
||||
2. *
|
||||
> print text=form-file-fail
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: web.use middleware smoke
|
||||
description: First-class middleware via web.use (replaces configure junk drawer).
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`headers` =
|
||||
|
||||
| header | value |
|
||||
|--------|-------|
|
||||
| X-Content-Type-Options | nosniff |
|
||||
| X-Frame-Options | DENY |
|
||||
|
||||
**pg = > web.page title="use-smoke"**
|
||||
**app = > web.app page=`pg`**
|
||||
**app = > web.use app=`app` middleware=`headers`**
|
||||
**mw = [middleware](app)**
|
||||
**sec = [security](mw)**
|
||||
1. `sec`
|
||||
> print text=use-ok
|
||||
2. *
|
||||
> print text=use-fail
|
||||
@@ -1,82 +0,0 @@
|
||||
---
|
||||
title: web W7 finish smoke — unique index, sitemap, cache-control (offline)
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**store = > web.db url="sqlite:web-fixtures/data/w7-smoke.db"**
|
||||
> `store`.exec sql="DROP TABLE IF EXISTS posts"
|
||||
|
||||
`fields` =
|
||||
|
||||
| 字段 | 类型 | 可空 | 唯一 | 索引 |
|
||||
|------|------|------|------|------|
|
||||
| id | int | 否 | | |
|
||||
| slug | text | 否 | 是 | 是 |
|
||||
| title | text | 否 | | |
|
||||
|
||||
> `store`.init name=posts fields=`fields`
|
||||
|
||||
**idx = > `store`.query sql="SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='posts'"**
|
||||
**nidx = > len value=[rows](idx)**
|
||||
1. `nidx` >= 1
|
||||
> print text=unique-ok
|
||||
2. *
|
||||
> print text=unique-fail
|
||||
|
||||
`items` =
|
||||
|
||||
| loc | 更新 |
|
||||
|-----|------|
|
||||
| / | 2026-08-28 |
|
||||
| /about | 2026-08-28 |
|
||||
|
||||
**sm = > web_sitemap_build base="https://example.com" items=`items`**
|
||||
**xml = [xml](sm)**
|
||||
1. `xml`
|
||||
> print text=sitemap-ok
|
||||
2. *
|
||||
> print text=sitemap-fail
|
||||
|
||||
**pg = > web.page title="w7"**
|
||||
**notfound = > web.page title="Missing"**
|
||||
**app = > web.app page=`pg` port=18120**
|
||||
**app = > `app`.configure cache_control="public, max-age=60" access_log=False**
|
||||
**app = > `app`.redirect from="/old" to="/new" permanent=True**
|
||||
**app = > `app`.error_page status=404 page=`notfound`**
|
||||
**app = > `app`.sitemap path="/sitemap.xml" base="https://example.com" items=`items`**
|
||||
**app = > `app`.robots sitemap="https://example.com/sitemap.xml"**
|
||||
**rd = [redirects](app)**
|
||||
**has = [/old](rd)**
|
||||
1. `has`
|
||||
> print text=redirect-ok
|
||||
2. *
|
||||
> print text=redirect-fail
|
||||
|
||||
**rb = [robots_body](app)**
|
||||
1. `rb`
|
||||
> print text=robots-ok
|
||||
2. *
|
||||
> print text=robots-fail
|
||||
|
||||
**mw = [middleware](app)**
|
||||
**cc = [cache_control](mw)**
|
||||
1. `cc` == "public, max-age=60"
|
||||
> print text=cache-control-ok
|
||||
2. *
|
||||
> print text=cache-control-fail
|
||||
|
||||
**p404 = [page_404](app)**
|
||||
1. `p404`
|
||||
> print text=error-page-ok
|
||||
2. *
|
||||
> print text=error-page-fail
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
title: web W7 live server — 404, redirect, sitemap, robots, cache-control
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
`items` =
|
||||
|
||||
| loc | note |
|
||||
|-----|------|
|
||||
| / | home |
|
||||
| /about | about |
|
||||
|
||||
**pg = > web.page title="w7-live"**
|
||||
**nf = > web.page title="Not Found Page"**
|
||||
**app = > web.app page=`pg` port=18121**
|
||||
**app = > `app`.configure cache_control="public, max-age=120"**
|
||||
**app = > `app`.redirect from="/legacy" to="/" permanent=True**
|
||||
**app = > `app`.error_page status=404 page=`nf`**
|
||||
**app = > `app`.sitemap path="/sitemap.xml" base="http://127.0.0.1:18121" items=`items`**
|
||||
**app = > `app`.robots sitemap="http://127.0.0.1:18121/sitemap.xml"**
|
||||
> `app`.listen
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
title: web ws broadcast live server
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**pg = > web.page title="ws-live"**
|
||||
**app = > web.app page=`pg` port=18112**
|
||||
**app = > `app`.configure access_log=True**
|
||||
**app = > `app`.route_ws path="/room" mode="broadcast" require_auth=False**
|
||||
> `app`.listen
|
||||
@@ -1,33 +0,0 @@
|
||||
---
|
||||
title: web ws broadcast + access_log smoke (offline)
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
**pg = > web.page title="w6b"**
|
||||
**app = > web.app page=`pg` port=18111**
|
||||
**app = > `app`.route_ws path="/room" mode="broadcast"**
|
||||
**routes = [ws_routes](app)**
|
||||
**room = [/room](routes)**
|
||||
**mode = [mode](room)**
|
||||
1. `mode` == "broadcast"
|
||||
> print text=ws-broadcast-route-ok
|
||||
2. *
|
||||
> print text=ws-broadcast-route-fail
|
||||
|
||||
**app = > `app`.configure access_log=True compress=False**
|
||||
**mw = [middleware](app)**
|
||||
**al = [access_log](mw)**
|
||||
1. `al`
|
||||
> print text=access-log-ok
|
||||
2. *
|
||||
> print text=access-log-fail
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
title: web WS room + on_message bag smoke
|
||||
description: route_ws mode=room stores room_key, on_message, presence
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**首页 = > web.page title="ws"**
|
||||
**应用 = > web.app page=`首页` admin=False**
|
||||
**应用 = > `应用`.route_ws path="/chat/{id}" mode="room" room_key="chat.room.{id}" on_message="chat.persist" presence=True**
|
||||
**routes = > json.get value=`应用` key="ws_routes"**
|
||||
**spec = > json.get value=`routes` key="/chat/{id}"**
|
||||
**mode = > json.get value=`spec` key="mode"**
|
||||
**rk = > json.get value=`spec` key="room_key"**
|
||||
**om = > json.get value=`spec` key="on_message"**
|
||||
**pr = > json.get value=`spec` key="presence"**
|
||||
1. `mode` == "room"
|
||||
1. `rk` == "chat.room.{id}"
|
||||
1. `om` == "chat.persist"
|
||||
1. `pr` == True
|
||||
> print text=ws-room-bag-ok
|
||||
2. *
|
||||
> print text=presence-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=on-message-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=room-key-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=mode-fail
|
||||
> sys.exit code=1
|
||||
@@ -1,82 +0,0 @@
|
||||
---
|
||||
title: web zh API smoke
|
||||
description: Offline Chinese 网页.mq.md assemble (no listen).
|
||||
导入 网页:ext/web/网页.mq.md
|
||||
import nav:web-fixtures/components/nav.mq.md
|
||||
import side:web-fixtures/components/side.mq.md
|
||||
import foot:web-fixtures/components/foot.mq.md
|
||||
import articles:web-fixtures/db/articles.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**store = > 网页.数据库 地址="sqlite:web-fixtures/data/zh-smoke.db"**
|
||||
**schema = > articles.schema**
|
||||
> `store`.初始化 名=articles 字段=`schema`
|
||||
> `store`.执行 sql="DELETE FROM articles"
|
||||
> `store`.执行 sql="DELETE FROM sqlite_sequence WHERE name='articles'"
|
||||
|
||||
`layout` =
|
||||
|
||||
| 组件 | 样式 |
|
||||
|------|------|
|
||||
| nav.`nav` | |
|
||||
| side.`side` | |
|
||||
| foot.`foot` | |
|
||||
|
||||
`index` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | articles.`articles`.title | |
|
||||
| body | articles.`articles`.body | |
|
||||
|
||||
`seed` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| 中文种子 | 正文 |
|
||||
|
||||
> `store`.插入 表=articles 行=`seed`
|
||||
|
||||
**page = > 网页.页面 标题="中文烟测" 引言="<h1>中文</h1>"**
|
||||
**page = > `page`.组件装配 组件=`layout`**
|
||||
**page = > `page`.主体装配 主体=`index`**
|
||||
|
||||
**html = > `page`.渲染 数据库=`store`**
|
||||
1. `html`
|
||||
> print text=render-ok
|
||||
2. *
|
||||
> print text=render-fail
|
||||
|
||||
**nav = > json.get value=`page` key="nav"**
|
||||
1. `nav`
|
||||
> print text=compose-ok
|
||||
2. *
|
||||
> print text=compose-fail
|
||||
|
||||
`fields` =
|
||||
|
||||
| 字段 | 标签 | 类型 | 必填 | 默认 |
|
||||
|------|------|------|------|------|
|
||||
| title | 标题 | text | true | |
|
||||
|
||||
**f = > 网页.表单 表="articles" 动作="插入"**
|
||||
**f = > `f`.字段 字段=`fields`**
|
||||
**page = > `page`.表单装配 id="article" 表单=`f`**
|
||||
**fid = > json.get value=`page` key="form_id"**
|
||||
1. `fid` == "article"
|
||||
> print text=form-ok
|
||||
2. *
|
||||
> print text=form-fail
|
||||
|
||||
**app = > 网页.应用 页面=`page` 数据库=`store` 主机=127.0.0.1 端口=18082**
|
||||
**about = > 网页.页面 标题="关于" 引言="<p>关于</p>"**
|
||||
**app = > `app`.路由 路径="/about" 页面=`about`**
|
||||
**routes = > json.get value=`app` key="routes"**
|
||||
**routed = > json.get value=`routes` key="/about"**
|
||||
1. `routed`
|
||||
> print text=route-ok
|
||||
2. *
|
||||
> print text=route-fail
|
||||
Reference in new issue
Block a user