mirror of
https://github.com/penpot/penpot.git
synced 2026-11-18 16:12:24 +00:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
3f6c69bb6a
@ -13,19 +13,17 @@ Multi-dimensional code review with quality gates. Every change gets reviewed bef
|
||||
|
||||
## When to Use
|
||||
|
||||
- The reviewer subagent of the `review-code` flow loads this skill to perform
|
||||
the review of a code change.
|
||||
- To review code, always go through the `review-code` flow — never load this
|
||||
skill directly for that. This is the criteria reference, not the flow.
|
||||
- The reviewer subagent of the `review-code` flow loads this skill to perform the review of a code change.
|
||||
- To review code, always go through the `review-code` flow — never load this skill directly for that. This is the criteria reference, not the flow.
|
||||
|
||||
## Core Principles
|
||||
|
||||
These principles underpin every axis. When in doubt, default to them.
|
||||
|
||||
- **DRY (Don't Repeat Yourself):** Every piece of knowledge has one authoritative representation. If the same logic appears in two places, extract it into a shared helper, model, or type. Reviewers: flag duplicated logic as a required change — it's not "just similar," it's drift that will diverge.
|
||||
- **KISS (Keep It Simple, Stupid):** The simplest solution that works is the best solution. Complexity must earn its place. Reviewers: if you need more than one sentence to explain what a piece of code does, it's too complex — push for simplification before merge.
|
||||
- **YAGNI (You Aren't Gonna Need It):** Don't add abstractions, hooks, or generalizations for hypothetical future use cases. Generalize on the third occurrence, not the first. Reviewers: delete speculative generality.
|
||||
- **Don't invent problems:** Do not manufacture issues to produce more feedback. Every finding must be a real risk, a real readability barrier, or a real architectural concern — not a hypothetical or a stylistic preference disguised as a problem.
|
||||
- **DRY (Don't Repeat Yourself):** Every piece of knowledge has one authoritative representation. Flag duplicated logic as a required change — it is not "just similar", it is drift that will diverge.
|
||||
- **KISS (Keep It Simple, Stupid):** The simplest solution that works is the best solution. Complexity must earn its place: if it needs more than a sentence to explain, push for simplification before merge.
|
||||
- **YAGNI (You Aren't Gonna Need It):** No abstractions, hooks or generalizations for hypothetical future use cases. Generalize on the third occurrence, not the first.
|
||||
- **Don't invent problems:** Every finding must be a real risk, a real readability barrier, or a real architectural concern — not a hypothetical or a stylistic preference disguised as a problem.
|
||||
|
||||
## The Five-Axis Review
|
||||
|
||||
@ -38,7 +36,7 @@ Does the code do what it claims to do?
|
||||
- Does it match the spec or task requirements?
|
||||
- Are edge cases handled (null, empty, boundary values)?
|
||||
- Are error paths handled (not just the happy path)?
|
||||
- Does it pass all tests? Are the tests actually testing the right things?
|
||||
- Do the tests cover the changed behavior, including its edge cases?
|
||||
- Are there off-by-one errors, race conditions, or state inconsistencies?
|
||||
|
||||
### 2. Readability & Simplicity
|
||||
@ -47,10 +45,7 @@ Can another engineer (or agent) understand this code without the author explaini
|
||||
|
||||
- Are names descriptive and consistent with project conventions? (No `temp`, `data`, `result` without context)
|
||||
- Is the control flow straightforward (avoid nested ternaries, deep callbacks)?
|
||||
- Are there any "clever" tricks that should be simplified?
|
||||
- **KISS check:** Is this the simplest approach that solves the problem? A 20-line straightforward function beats a 5-line clever one that requires a comment to explain.
|
||||
- Could this be done in fewer lines? (1000 lines where 100 suffice is a failure)
|
||||
- Are abstractions earning their complexity? (Don't generalize until the third use case)
|
||||
- Are there "clever" tricks that should be simplified? Could this be done in fewer lines? (1000 lines where 100 suffice is a failure)
|
||||
- Is a new conditional bolted onto an unrelated flow? Push the logic into its own helper, state, or policy.
|
||||
- Do repeated conditionals on the same shape appear? They signal a missing model or dispatcher.
|
||||
- Are there dead code artifacts: no-op variables, backwards-compat shims, or `// removed` comments?
|
||||
@ -60,14 +55,13 @@ Can another engineer (or agent) understand this code without the author explaini
|
||||
Does the change fit the system's design?
|
||||
|
||||
- Does it follow existing patterns or introduce a new one? If new, is it justified?
|
||||
- Does it maintain clean module boundaries?
|
||||
- **DRY check:** Is there existing code that does the same thing? Reuse the canonical helper instead of writing a near-duplicate. If two branches do nearly the same thing, collapse them.
|
||||
- Are dependencies flowing in the right direction (no circular dependencies)?
|
||||
- Does it keep clean module boundaries, with dependencies flowing the right way (no cycles)?
|
||||
- Is the abstraction level appropriate (not over-engineered, not too coupled)?
|
||||
- Does this refactor reduce complexity or just relocate it? Count the concepts a reader must hold. Prefer the restructuring that makes whole branches disappear over one that re-centralizes the same logic. Prefer deleting an abstraction to polishing it.
|
||||
- Is there existing code that already does this? Reuse the canonical helper instead of a near-duplicate, and collapse branches that do nearly the same thing.
|
||||
- Is feature-specific logic leaking into a shared or general-purpose module?
|
||||
- Are type boundaries explicit? Question gratuitous `any`/`unknown`/optional/casts and silent fallbacks.
|
||||
- **Structural remedies:** When you flag a problem, propose the move — not just the problem. Replace conditionals with dispatchers, collapse duplicate branches, separate orchestration from business logic, extract helpers, split large files. Prefer the remedy that removes moving pieces over one that spreads the same complexity around.
|
||||
- Does the change reduce complexity or relocate it? Count the concepts a reader must hold: prefer the restructuring that makes whole branches disappear, and deleting an abstraction over polishing it.
|
||||
- **Give the remedy, not only the problem:** replace conditionals with dispatchers, separate orchestration from business logic, extract helpers, split large files. Prefer the remedy that removes moving pieces over one that spreads the same complexity around.
|
||||
|
||||
### 4. Security
|
||||
|
||||
@ -111,7 +105,17 @@ For each finding, describe the circumstances under which it could fail: specific
|
||||
|
||||
Lead with what matters: correctness and security first, then structural issues, then everything else. A few high-conviction comments beat a long list.
|
||||
|
||||
5. **Verify the verification** — What tests were run? Did the build pass? Was the change tested manually? Screenshots for UI changes?
|
||||
5. **Check the evidence, do not re-run it** — Which tests cover the change? What did the author run, and what did CI report? Never re-run the full suite or a build yourself: the author's run and CI already cover that, and repeating it only lengthens the review. Run at most the single test file that settles a specific doubt. When no checks have been run at all (a change you did not see tested), run the module's checks before the verdict.
|
||||
|
||||
## Change Sizing
|
||||
|
||||
Small, focused changes are easier to review, faster to merge, and safer to deploy. Flag the size when a diff exceeds ~300 lines, or when it grows a file past ~1000 total lines, and name the remedy: split it, and separate refactoring from feature work. This is a finding about the change, not work to do inside the review.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Before accepting a new dependency: does the existing stack already solve it, how large is the bundle impact, is it maintained, does `npm audit` report anything, is the license compatible. Prefer the standard library and existing utilities — every dependency is a liability.
|
||||
|
||||
For upgrades: read the changelog, not just the version number; one dependency per change; a green suite before and after; review the lockfile diff and never hand-edit it. Supply-chain triage follows `security-and-hardening`.
|
||||
|
||||
## Review Output
|
||||
|
||||
@ -151,96 +155,18 @@ Choose one:
|
||||
|
||||
List the finding IDs the verdict depends on (e.g. "Request changes: R1, R2").
|
||||
|
||||
## Change Sizing
|
||||
|
||||
Small, focused changes are easier to review, faster to merge, and safer to deploy.
|
||||
|
||||
```
|
||||
~100 lines changed → Good. Reviewable in one sitting.
|
||||
~300 lines changed → Acceptable if it's a single logical change.
|
||||
~1000 lines changed → Too large. Split it.
|
||||
```
|
||||
|
||||
**Watch file size, not just diff size.** Around 1000 *total* lines in a single file is a common inspection signal. When a change materially grows an already-large file, decompose first.
|
||||
|
||||
**Splitting strategies:**
|
||||
|
||||
| Strategy | How | When |
|
||||
|----------|-----|------|
|
||||
| **Stack** | Submit a small change, start the next one based on it | Sequential dependencies |
|
||||
| **By file group** | Separate changes for groups needing different reviewers | Cross-cutting concerns |
|
||||
| **Horizontal** | Create shared code/stubs first, then consumers | Layered architecture |
|
||||
| **Vertical** | Break into smaller full-stack slices of the feature | Feature work |
|
||||
|
||||
**Separate refactoring from feature work.** A change that refactors and adds new behavior is two changes — submit them separately.
|
||||
|
||||
## Change Descriptions
|
||||
|
||||
- **First line:** Short, imperative, standalone. "Delete the FizzBuzz RPC" not "Deleting the FizzBuzz RPC."
|
||||
- **Body:** What is changing and why. Include context and reasoning not visible in the code itself.
|
||||
- **Anti-patterns:** "Fix bug," "Fix build," "Add patch," "Phase 1."
|
||||
|
||||
## Dependencies
|
||||
|
||||
Before adding any dependency:
|
||||
|
||||
1. Does the existing stack solve this? (Often it does.)
|
||||
2. How large is the dependency? (Check bundle impact.)
|
||||
3. Is it actively maintained? (Check last commit, open issues.)
|
||||
4. Does it have known vulnerabilities? (`npm audit`)
|
||||
5. What's the license? (Must be compatible with the project.)
|
||||
|
||||
**Rule:** Prefer standard library and existing utilities over new dependencies. Every dependency is a liability.
|
||||
|
||||
**Upgrading dependencies:**
|
||||
|
||||
- Read the changelog, not just the version number. Semver is a promise the maintainer may not have kept.
|
||||
- One dependency per change. When a bulk bump breaks the build, you've lost which package did it.
|
||||
- Let the tests decide — a green suite before *and* after, not just "it installed."
|
||||
- Review the lockfile diff, not just `package.json`. Commit it and never hand-edit it.
|
||||
|
||||
For supply-chain risk triage, follow the `security-and-hardening` skill.
|
||||
|
||||
## Common Rationalizations
|
||||
|
||||
| Rationalization | Reality |
|
||||
|---|---|
|
||||
| "It works, that's good enough" | Working code that's unreadable, insecure, or architecturally wrong creates debt that compounds. |
|
||||
| "I wrote it, so I know it's correct" | Authors are blind to their own assumptions. Every change benefits from another set of eyes. |
|
||||
| "We'll clean it up later" | Later never comes. The review is the quality gate — use it. |
|
||||
| "AI-generated code is probably fine" | AI code needs more scrutiny, not less. It's confident and plausible, even when wrong. |
|
||||
| "The tests pass, so it's good" | Tests are necessary but not sufficient. They don't catch architecture, security, or readability problems. |
|
||||
| "The refactor makes it cleaner" | Relocating complexity isn't reducing it. If the reader still holds the same number of concepts, the structure didn't improve. |
|
||||
| "It's only a small addition to this file" | Small diffs still push files past healthy size and bolt branches onto unrelated flows. |
|
||||
| "It's just a version bump" | A bump is a behavior change you didn't write. Read the changelog. |
|
||||
| "I'll upgrade everything in one PR" | A bulk bump hides which package broke the build. One per change. |
|
||||
| "It's duplicated but it's only two places" | Two becomes three becomes five. Extract now, before the copies diverge. |
|
||||
| "The abstraction is future-proof" | YAGNI. Delete speculative generality — generalize on the third occurrence, not the first. |
|
||||
| "It's clever but efficient" | Cleverness is a readability tax. If it needs a comment to understand, simplify it. |
|
||||
|
||||
## Red Flags
|
||||
|
||||
- PRs merged without any review
|
||||
- Review that only checks if tests pass (ignoring other axes)
|
||||
- "LGTM" without evidence of actual review
|
||||
- Security-sensitive changes without security-focused review
|
||||
- Large PRs that are "too big to review properly" (split them)
|
||||
- No regression tests with bug fix PRs
|
||||
- Accepting "I'll fix it later" — it never happens
|
||||
- A refactor that moves code around without reducing the number of concepts a reader must hold
|
||||
- New conditionals scattered into unrelated code paths (a missing abstraction)
|
||||
- A bespoke helper that duplicates an existing canonical one
|
||||
- A bulk "bump dependencies" PR with no changelog review
|
||||
- A change merged without any review.
|
||||
- A review that only checks whether the tests pass.
|
||||
- Security-sensitive changes without a security-focused review.
|
||||
- A change too large to review properly: split it.
|
||||
|
||||
## Verification
|
||||
|
||||
Before emitting the verdict, verify the change as it stands. This is the reviewer's own due diligence — it covers the state of the code at review time, not the later resolution of findings (fixing findings is the author's job; confirming them is a new review):
|
||||
Before emitting the verdict, confirm the evidence the review rests on. This covers the state of the code at review time, not the later fixing of findings:
|
||||
|
||||
- [ ] Tests pass — run them yourself, don't trust the claim
|
||||
- [ ] Build succeeds
|
||||
- [ ] The verification story is documented (what changed, how it was verified)
|
||||
- [ ] Dependency upgrades reviewed against changelog, isolated per package, verified by green suite
|
||||
|
||||
## See Also
|
||||
|
||||
- For detailed security review guidance, see `security-and-hardening`
|
||||
- [ ] The suite is green, and the evidence is the author's run or CI — not your own re-run. Say which one you relied on.
|
||||
- [ ] New behavior has tests that cover the edge cases in the diff.
|
||||
- [ ] The verification story is stated: what changed and how it was verified.
|
||||
- [ ] Dependency changes were reviewed against the changelog and the lockfile diff.
|
||||
|
||||
@ -63,6 +63,8 @@ subject/body limits, and the `AI-assisted-by` trailer. Follow it exactly.
|
||||
- Do not pass `--author`. Author identity comes from the local git config.
|
||||
- Do not amend a commit you did not create in this session, unless explicitly asked.
|
||||
- Do not bypass pre-commit hooks (`--no-verify`) unless explicitly asked.
|
||||
- Never add a `Co-authored-by:` trailer. It is forbidden and fails `./scripts/check-commit`.
|
||||
- Add `Co-authored-by:` only for a human co-author. AI providers, agents and
|
||||
bots are rejected by `./scripts/check-commit`; for AI participation use the
|
||||
`AI-assisted-by:` trailer.
|
||||
- Do not add untracked files that were not created in this session.
|
||||
- Do not skip the `scripts/check-commit` verification step (Iron Rule 4).
|
||||
|
||||
@ -22,8 +22,20 @@ Act as a senior software engineer and perform a thorough code review.
|
||||
diff, a commit range, a branch, a PR (number or URL), or specific files. If
|
||||
the target is ambiguous, ask before reviewing.
|
||||
2. Delegate the review to the `general` subagent (via the task tool), unless the
|
||||
user specifies another agent. Include in the prompt the
|
||||
**`code-review-criteria`** skill name and all user context.
|
||||
user specifies another agent. The prompt carries the **`code-review-criteria`**
|
||||
skill name, all user context, and these requirements:
|
||||
- Load `code-review-criteria` and follow its process and output format.
|
||||
- Read `AGENTS.md` (if present) and the module memories it points to for the
|
||||
code being reviewed.
|
||||
- Return the COMPLETE review, verbatim, exactly as the skill instructs it to
|
||||
be produced. Never summarize it.
|
||||
- Read-only: modify no file and create no commit. Reviewing never writes.
|
||||
- Do not invent problems: every finding must be real and actionable.
|
||||
- Missing tests are an issue, not a suggestion — a severity-tagged finding.
|
||||
- Prioritize by impact: one structural issue outweighs ten nits, and "this
|
||||
could be better" is not a finding — say why and how.
|
||||
- Skip generated files, lockfile-only changes and unrelated modifications
|
||||
unless they introduce security risks.
|
||||
3. When the subagent returns, output the review to the user verbatim. Do not
|
||||
summarize it and do not act on its findings.
|
||||
4. Right after the review, suggest how to proceed based on the findings. These
|
||||
@ -44,43 +56,18 @@ the findings. Once the user explicitly states the review is done (or moves on to
|
||||
a different task), this rule no longer applies and you act as a normal build
|
||||
agent again.
|
||||
|
||||
## Instructions for the subagent
|
||||
|
||||
1. Load the **`code-review-criteria`** skill and follow its process and output
|
||||
format.
|
||||
2. Read `AGENTS.md` (if present) and follow its instructions for finding and
|
||||
reading all related testing documentation from memories before reviewing.
|
||||
3. Return in your final message the COMPLETE review, verbatim, exactly as the
|
||||
skill instructs it to be produced. Do not summarize it — include the full
|
||||
structured review.
|
||||
|
||||
### Strong rules for the subagent
|
||||
|
||||
1. Do not invent problems. Every finding must be real and actionable.
|
||||
2. Read-only: do not modify any file and do not create a commit — reviewing
|
||||
never writes.
|
||||
3. Be specific and constructive. "This could be better" is not helpful — explain
|
||||
why and how.
|
||||
4. Prioritize by impact. One structural issue outweighs ten nits.
|
||||
5. Missing tests are an issue, not a suggestion. Report as a severity-tagged
|
||||
finding — never as a recommendation.
|
||||
6. Skip generated files, lockfile-only changes, and unrelated modifications
|
||||
unless they introduce security risks.
|
||||
|
||||
## Posting as a GitHub comment
|
||||
|
||||
Only post the review as a comment when the user asks for it explicitly. Keep
|
||||
it in the session otherwise.
|
||||
|
||||
When posting: PR comments go in English, with this minimal structure:
|
||||
Post only when the user asks for it explicitly; otherwise keep the review in the
|
||||
session. PR comments go in English, with this minimal structure:
|
||||
|
||||
1. **Intro line** — one sentence: what was found and the overall tone. No
|
||||
greetings.
|
||||
2. **`## Main issues`** — one subsection per required finding: what breaks,
|
||||
the failure circumstances, and the minimal fix (code snippet when useful).
|
||||
A missing test belongs here, not under minor suggestions.
|
||||
3. **`## Minor suggestions`** — one bullet per minor finding or suggestion:
|
||||
file/function, problem, concrete remedy.
|
||||
2. **`## Main issues`** — one subsection per required finding: what breaks, the
|
||||
failure circumstances, and the minimal fix (code snippet when useful). A
|
||||
missing test belongs here, not under minor suggestions.
|
||||
3. **`## Minor suggestions`** — one bullet per minor finding: file/function,
|
||||
problem, concrete remedy.
|
||||
4. **Closing** — optional and short. Cut it when it adds nothing.
|
||||
|
||||
Reference every finding by its ID (`R1`, `M1`, `S1`, … from
|
||||
|
||||
@ -53,6 +53,7 @@
|
||||
|
||||
- `app.config/config` and `flags` are dynamic `defonce` vars populated from `PENPOT_*` env vars through the shared schema string transformer. Tests and tooling can bind them.
|
||||
- Duration config values are parsed as ISO-8601 with the `PT` prefix, so a day is written in hours (`:jobs-retention` and `:jobs-user-ttl` default to a week, and an operator writes `168h`): `7d` does not parse, and the value fails validation at boot instead of being silently ignored.
|
||||
- `app.main` wires `PENPOT_DATABASE_*` into `::db/pool`, and `app.db/create-datasource-config` forwards pgjdbc's own knobs as `dataSourceProperties`, which `Properties.getProperty` silently drops unless the value is a String (hence the `str`). A query parameter of the same name in `PENPOT_DATABASE_URI` (for example `?prepareThreshold=0`) wins over the property: pgjdbc ignores the Properties value when the URL carries it, so the URI is the place to look when a variable seems to do nothing. The prepared statement cache is three optional `PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_*` keys: the threshold is the executions before a statement is server-prepared and accepts `-1` or non-negatives (`{:min -1}`; the driver clamps any other negative to `-1`, so rejecting it only turns a typo into a boot error), its `0` stops server-side prepared statements while the driver's client-side cache of parsed queries stays in use, `..._QUERIES` and `..._SIZE` reject negatives and `0` in either disables that cache, and the size is bytes rounded up to the whole MiB the driver accepts. Do not describe the threshold `0` as disabling the cache: it only stops the server-side prepares.
|
||||
- `parse-flags` automatically adds `:disable-secure-session-cookies` when `public-uri` is plain HTTP and not localhost. This changes cookie defaults without an explicit env flag.
|
||||
- The backend sets Clojure `*assert*` globally from the `:backend-asserts` feature flag. Assertion-dependent checks can therefore differ by runtime flags.
|
||||
- Request body parsing is mostly POST-oriented and supports Transit JSON plus plain JSON. Plain JSON request keys are kebab-decoded before being merged into `:params`. A body the parser cannot read is a client error, classified at the parse site and never by exception class (`clojure.data.json` signals its syntax errors with a bare `java.lang.Exception`): 400 `:validation`/`:malformed-json`, one `warn` line (`malformed request body`) carrying path, peer address and content-type instead of a stack trace, and `penpot_http_malformed_requests_total`. `RequestTooBigException` keeps its 413.
|
||||
|
||||
@ -37,5 +37,7 @@
|
||||
- Plugin listeners are watches on the global store and callbacks are debounced about 10ms. Callback exceptions are caught and logged so plugin code does not crash the app.
|
||||
- `selectionchange` callbacks receive arrays of shape id strings, while `filechange`, `pagechange`, and `shapechange` return proxies.
|
||||
- `contentsave` fires only when persistence status transitions to `:saved`; it calls the callback with no value.
|
||||
- `penpot.waitForSave(timeout?)` (`app.plugins.persist/wait-for-save`; runtime forwarder checks `content:read`) waits on the **shared** persistence queue, not only the plugin's own commits. Flow: ~100ms intake race (buffer/queue non-empty vs deadline, capped to the timeout) → empty resolves; pending emits `::dps/force-persist` and races `dps/wait-persisted-or-error` against `::dps/rollback-rejected` / `::dps/rolled-back` (rollback rejects even if status later reads `:saved`). Default 60s. `:error` status at intake rejects at once (`earlier-failure`): `save-retrying` while `dps/save-retrying?` (slow retry cycle, recovers by itself), otherwise the stored `[:error :code]` with reopen advice (a terminal failure stays until the file is reopened, so it fails every call). Rejections are `Error`s with `code`: `save-timeout`, `rolled-back`, `save-retrying`, or the failure code (`save-failed` unless the backend gave one).
|
||||
- Plugin timeouts validate through `u/valid-timeout?` (positive finite number ≤ `u/max-timeout`, signed 32-bit) and reject through `u/reject-not-valid`, which rejects an `Error` (never a bare string) so callers can read `.message`.
|
||||
- `contentrollback` is not a state watch: it subscribes to `st/stream` for `::dps/rolled-back` (kept in `subscriptions`, disposed by `remove-listener`), not debounced, delivered async so the reverted state is in place. Payload `{fileIds pageIds shapeIds}` from `pcm/rollback-targets` (page shapes only, from the reverted commits' redo changes). When the rollback falls back to reloading the file, `::dps/rolled-back` waits for the reloaded data, so the callback never reads the rejected data. The runtime's `validEvents` must list every event name, or `penpot.on` rejects it; a stale runtime build rejects new events. The MCP plugin forwards these rollbacks with the next task response and the server puts a warning first in that tool response (`RollbackNotices`). Unsent ones survive a tab or plugin reload in `penpot.localStorage` (key `rollbacks/<file-id>`, `LocalStorageRollbackStore`; the MCP manifest in `app.main.data.workspace.mcp` and `mcp/packages/plugin/public/manifest.json` grant `allow:localstorage`, which the runtime checks on access); the entry goes once a response carried them.
|
||||
- Plugin history `undoBlockBegin` creates a workspace undo transaction with a JS `Symbol`; `undoBlockFinish` commits that symbol. Missing finish eventually relies on the workspace transaction timeout.
|
||||
@ -120,6 +120,14 @@ From the `mcp/` directory, run
|
||||
|
||||
- Authorization/discovery URLs, self-contained client IDs, consent and PKCE/code binding, backend Redis state, deployment wiring, and compatibility limits: `mem:mcp/oauth`.
|
||||
|
||||
## Host and Origin allowlist (`RequestGuard`)
|
||||
|
||||
- `RequestGuard` checks `Host` and `Origin` (hostname only, port ignored) on `/mcp`, the REPL (Express middleware, 403) and the plugin WebSocket (close `1008` before any message is read). It stops web pages on the user's machine from driving a local server (DNS rebinding, cross-site WebSocket).
|
||||
- Allowlist: `PENPOT_MCP_ALLOWED_HOSTS` (`*` turns the check off); unset → loopback only in single-user mode (local or remote: no other barrier, `execute_code` still runs in the user's session), any host in multi-user mode (relies on user tokens; behind nginx `/mcp/ws` the server sees `Host: penpot-mcp:4402`). A missing `Origin` passes (non-browser clients).
|
||||
- Entries must be `*`, a hostname or a bracketed IPv6 address; one with a scheme, port or path makes `fromEnvironment` throw, so the server does not start. Startup logs a `warn` when the check is off in single-user mode.
|
||||
- The plugin iframe has `allow-same-origin`, so its WebSocket carries the real plugin origin (`http://localhost:4400` locally, the Penpot origin when integrated).
|
||||
- Test mocks of `PenpotMcpServer` passed to `PluginBridge` must provide `requestGuard`.
|
||||
|
||||
## Backend tools (`submit_feedback`)
|
||||
|
||||
- Tools that call the Penpot backend directly (not through the plugin) register only when `PENPOT_MCP_BACKEND_URI` is nonblank (`PenpotMcpServer.initTools`). Currently only `SubmitFeedbackTool`.
|
||||
@ -140,10 +148,11 @@ For parallel devenvs, prefer same-origin MCP routing: each Penpot instance shoul
|
||||
## Plugin reconnect policy
|
||||
|
||||
- The plugin treats WebSocket close code `1008` (policy violation) as terminal: it stops auto-reconnecting and stays disconnected until the user explicitly reconnects. Other close codes keep the capped-backoff retry. The decision lives in `ReconnectPolicy.ts` (`shouldReconnectAfterClose`), kept as a pure module so it is unit-testable without DOM/CSS.
|
||||
- The MCP server emits `1008` for a missing `userToken` in multi-user mode, for missing/invalid connection metadata, and to close a connection displaced by a newer one with the same user and session ID.
|
||||
- The MCP server emits `1008` for a `Host`/`Origin` outside the `RequestGuard` allowlist, for a missing `userToken` in multi-user mode, for missing/invalid connection metadata, and to close a connection displaced by a newer one with the same user and session ID.
|
||||
- Session IDs are deterministic per tab and file, so a reconnect reuses its ID while the old socket may be half-open: the newest connection wins (`PluginBridge.displaceConnection`). Across instances, each new connection publishes a session claim on a per-user Redis channel; an instance displaces its local connection only on a foreign claim that arrives after its own claim (channel order, no clocks). Discovery deduplicates by session ID.
|
||||
- A tab rejected with `1008` never reaches `connected`, so the frontend's 60s reconnect watcher (`start-reconnect-watcher` in `app.main.data.workspace.mcp`, started only on `connected`) does not engage; recovery is manual via the MCP menu.
|
||||
|
||||
## Rollback warnings
|
||||
|
||||
- `ExecuteCodeTaskHandler` awaits `penpot.waitForSave()` after the code and outside its swallow catch, so a save failure, save timeout or rollback during the wait fails that `execute_code` call itself. It hard-fails as "missing Plugin API support" when `penpot.waitForSave` is absent (old Penpot or stale runtime build, or broken `api.cljs` wiring). Both waits run only when `penpotMgmt.workspace.status` is `"ready"` (or there is no `penpotMgmt`), checked at each wait: dashboard calls skip them, because persistence `:error` outlives the workspace and would fail successful `penpotMgmt` calls. Budget: layout wait 30s before the code + save wait 60s after it, under `PENPOT_MCP_TOOL_TIMEOUT_S` (120s). `RollbackNotices` below only cover rollbacks that land after the call returned (concurrent edits, a response after a timeout).
|
||||
- The plugin's `RollbackLog` (`packages/plugin/src/RollbackLog.ts`) holds the `contentrollback` events not yet sent with a task response; `Task.sendResponse` attaches them and acknowledges them once sent, and the server's `unclaimed-rollbacks` message (a response that came after its task timed out) puts them back. With a `RollbackStore` (`LocalStorageRollbackStore` over `penpot.localStorage`, one entry per file) every change is written through, so a reload of the tab or plugin keeps them; storage failures fall back to memory. Plugin tests run with `node --experimental-strip-types`, which rejects TypeScript parameter properties: declare fields explicitly.
|
||||
|
||||
@ -43,10 +43,9 @@ that breaks them is wrong, even if the code is right.
|
||||
- For another commit: `./scripts/check-commit -c <ref>`
|
||||
- **NEVER** hand-wave the body as "one long line". If a line exceeds 80,
|
||||
break it at a space.
|
||||
- **NEVER add a `Co-authored-by:` trailer.** It is forbidden; `scripts/check-commit` fails the commit when any line matches it (case-insensitive).
|
||||
- **`Co-authored-by:` is for human co-authors only** (`Co-authored-by: Name <email>`). AI providers, agents and bots must not be credited that way; use `AI-assisted-by:` instead. `scripts/check-commit` rejects a trailer value that names an AI provider or agent (`Claude`, `Copilot`, `Cursor`, `Codex`, `Gemini`, `Aider`, `Cline`, `Windsurf`, `DeepSeek`, `OpenCode`, `devin-ai`, `amazon q`, and similar) or carries a bot identity (`[bot]`, `bot@`). `NON_HUMAN_COAUTHOR_PATTERN` is the list; extend it when a new tool starts adding trailers. A person whose own name or email matches one of those tokens (a surname like `Cline`, an address at a provider) is rejected too; amend the trailer or credit them with `Reviewed-by:`.
|
||||
- CI runs `scripts/check-commit` on every new commit (`mem:workflow/creating-commits` is enforced by `.github/workflows/commit-checker.yml`), so a forbidden trailer fails the build.
|
||||
- Exceptions inside the body (do not wrap these): `Signed-off-by:`,
|
||||
`AI-assisted-by:` trailers, and lines carrying a URL.
|
||||
- Exceptions inside the body (do not wrap these): `Signed-off-by:`, `Co-authored-by:`, `AI-assisted-by:` trailers, and lines carrying a URL.
|
||||
|
||||
**AI-assisted-by trailer rules:**
|
||||
- Use only the model name, e.g. `mimo-v2.5`, `deepseek-v4-flash`
|
||||
|
||||
@ -244,8 +244,11 @@ Commit messages must follow this format:
|
||||
those prefixes to an existing subject)
|
||||
- **Wrap body lines at 80 characters or fewer** (trailers and URLs excepted)
|
||||
- Separate the subject from the body with a **blank line**
|
||||
- Never add a `Co-authored-by` trailer — it is forbidden and fails
|
||||
`./scripts/check-commit`
|
||||
- Use `Co-authored-by:` only for a human co-author
|
||||
(`Co-authored-by: Name <email>`). AI providers, agents and bots are not
|
||||
allowed there; for AI participation add an `AI-assisted-by: <model-name>`
|
||||
trailer instead. `./scripts/check-commit` rejects the trailer when its value
|
||||
names one of them.
|
||||
|
||||
You can check a commit against these rules with `./scripts/check-commit`.
|
||||
CI runs the same script on every new commit in
|
||||
|
||||
@ -40,7 +40,6 @@
|
||||
nrepl/nrepl {:mvn/version "1.8.0"}
|
||||
|
||||
org.postgresql/postgresql {:mvn/version "42.7.13"}
|
||||
org.xerial/sqlite-jdbc {:mvn/version "3.53.4.0"}
|
||||
|
||||
com.zaxxer/HikariCP {:mvn/version "7.1.0"}
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
[app.common.weak :as weak]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.db.sql :as sql]
|
||||
[app.features.fdata :as fdata]
|
||||
[app.features.file-migrations :as fmigr]
|
||||
[app.loggers.audit :as-alias audit]
|
||||
@ -129,18 +128,12 @@
|
||||
(defn initial-state
|
||||
[]
|
||||
{:storage-objects #{}
|
||||
:files #{}
|
||||
:teams #{}
|
||||
:projects #{}})
|
||||
:files #{}})
|
||||
|
||||
(defn collect-storage-objects
|
||||
[state items]
|
||||
(update state :storage-objects into xf-map-media-id items))
|
||||
|
||||
(defn collect-summary
|
||||
[state key items]
|
||||
(update state key into xf-map-media-id items))
|
||||
|
||||
(defn lookup-index
|
||||
[id]
|
||||
(when id
|
||||
@ -554,27 +547,6 @@
|
||||
[cfg project-id]
|
||||
(db/get cfg :project {:id project-id}))
|
||||
|
||||
(def ^:private sql:get-teams
|
||||
"SELECT t.* FROM team WHERE id = ANY(?)")
|
||||
|
||||
(defn get-teams
|
||||
[cfg ids]
|
||||
(let [conn (db/get-connection cfg)
|
||||
ids (db/create-array conn "uuid" ids)]
|
||||
(->> (db/exec! conn [sql:get-teams ids])
|
||||
(map decode-row-features))))
|
||||
|
||||
(defn get-team
|
||||
[cfg team-id]
|
||||
(-> (db/get cfg :team {:id team-id})
|
||||
(decode-row-features)))
|
||||
|
||||
(defn get-fonts
|
||||
[cfg team-id]
|
||||
(db/query cfg :team-font-variant
|
||||
{:team-id team-id
|
||||
:deleted-at nil}))
|
||||
|
||||
(def ^:private sql:get-files-rels
|
||||
"SELECT flr.*,
|
||||
fls.synced_at
|
||||
@ -656,15 +628,6 @@
|
||||
:deleted-at nil})
|
||||
(not-empty)))
|
||||
|
||||
(defn get-file-thumbnail
|
||||
"Return the thumbnail for the specified file-id"
|
||||
[cfg {:keys [id revn]}]
|
||||
(db/get* cfg :file-thumbnail
|
||||
{:file-id id
|
||||
:revn revn
|
||||
:data nil}
|
||||
{::sql/columns [:media-id :file-id :revn]}))
|
||||
|
||||
(def ^:private sql:get-missing-media-references
|
||||
"SELECT fmo.*
|
||||
FROM file_media_object AS fmo
|
||||
|
||||
@ -1,450 +0,0 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.binfile.v2
|
||||
"A sqlite3 based binary file exportation with support for exportation
|
||||
of entire team (or multiple teams) at once."
|
||||
(:refer-clojure :exclude [read])
|
||||
(:require
|
||||
[app.binfile.common :as bfc]
|
||||
[app.common.data :as d]
|
||||
[app.common.features :as cfeat]
|
||||
[app.common.logging :as l]
|
||||
[app.common.time :as ct]
|
||||
[app.common.transit :as t]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.db.sql :as sql]
|
||||
[app.loggers.audit :as-alias audit]
|
||||
[app.loggers.webhooks :as-alias webhooks]
|
||||
[app.storage :as sto]
|
||||
[app.storage.tmp :as tmp]
|
||||
[app.util.events :as events]
|
||||
[app.worker :as-alias wrk]
|
||||
[clojure.set :as set]
|
||||
[cuerdas.core :as str]
|
||||
[datoteka.io :as io]
|
||||
[promesa.util :as pu])
|
||||
(:import
|
||||
java.sql.DriverManager))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; LOW LEVEL API
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- create-database
|
||||
([cfg]
|
||||
(let [path (tmp/tempfile :prefix "penpot.binfile." :suffix ".sqlite")]
|
||||
(create-database cfg path)))
|
||||
([cfg path]
|
||||
(let [db (DriverManager/getConnection (str "jdbc:sqlite:" path))]
|
||||
(assoc cfg ::db db ::path path))))
|
||||
|
||||
(def ^:private
|
||||
sql:create-kvdata-table
|
||||
"CREATE TABLE kvdata (
|
||||
tag text NOT NULL,
|
||||
key text NOT NULL,
|
||||
val text NOT NULL,
|
||||
dat blob NULL
|
||||
)")
|
||||
|
||||
(def ^:private
|
||||
sql:create-kvdata-index
|
||||
"CREATE INDEX kvdata__tag_key__idx
|
||||
ON kvdata (tag, key)")
|
||||
|
||||
(defn- setup-schema!
|
||||
[{:keys [::db]}]
|
||||
(db/exec-one! db [sql:create-kvdata-table])
|
||||
(db/exec-one! db [sql:create-kvdata-index]))
|
||||
|
||||
(defn- write!
|
||||
[{:keys [::db]} tag k v & [data]]
|
||||
(db/insert! db :kvdata
|
||||
{:tag (d/name tag)
|
||||
:key (str k)
|
||||
:val (t/encode-str v {:type :json-verbose})
|
||||
:dat data}
|
||||
{::db/return-keys false}))
|
||||
|
||||
(defn- read-blob
|
||||
[{:keys [::db]} tag k]
|
||||
(let [obj (db/get db :kvdata
|
||||
{:tag (d/name tag)
|
||||
:key (str k)}
|
||||
{::sql/columns [:dat]})]
|
||||
(:dat obj)))
|
||||
|
||||
(defn- read-seq
|
||||
([{:keys [::db]} tag]
|
||||
(->> (db/query db :kvdata
|
||||
{:tag (d/name tag)}
|
||||
{::sql/columns [::val]})
|
||||
(map :val)
|
||||
(map t/decode-str)))
|
||||
([{:keys [::db]} tag k]
|
||||
(->> (db/query db :kvdata
|
||||
{:tag (d/name tag)
|
||||
:key (str k)}
|
||||
{::sql/columns [::val]})
|
||||
(map :val)
|
||||
(map t/decode-str))))
|
||||
|
||||
(defn- read-obj
|
||||
[{:keys [::db]} tag k]
|
||||
(let [obj (db/get db :kvdata
|
||||
{:tag (d/name tag)
|
||||
:key (str k)}
|
||||
{::sql/columns [:val]})]
|
||||
(-> obj :val t/decode-str)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; IMPORT/EXPORT IMPL
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(declare ^:private write-project!)
|
||||
(declare ^:private write-file!)
|
||||
|
||||
(defn- write-team!
|
||||
[cfg team-id]
|
||||
|
||||
(let [team (bfc/get-team cfg team-id)
|
||||
fonts (bfc/get-fonts cfg team-id)]
|
||||
|
||||
(events/tap :progress
|
||||
{:op :export
|
||||
:section :write-team
|
||||
:id team-id
|
||||
:name (:name team)})
|
||||
|
||||
(l/trc :hint "write" :obj "team"
|
||||
:id (str team-id)
|
||||
:fonts (count fonts))
|
||||
|
||||
(when-let [photo-id (:photo-id team)]
|
||||
(vswap! bfc/*state* update :storage-objects conj photo-id))
|
||||
|
||||
(vswap! bfc/*state* update :teams conj team-id)
|
||||
(vswap! bfc/*state* bfc/collect-storage-objects fonts)
|
||||
|
||||
(write! cfg :team team-id team)
|
||||
|
||||
(doseq [{:keys [id] :as font} fonts]
|
||||
(vswap! bfc/*state* update :team-font-variants conj id)
|
||||
(write! cfg :team-font-variant id font))))
|
||||
|
||||
(defn- write-project!
|
||||
[cfg project]
|
||||
(events/tap :progress
|
||||
{:op :export
|
||||
:section :write-project
|
||||
:id (:id project)
|
||||
:name (:name project)})
|
||||
(l/trc :hint "write" :obj "project" :id (str (:id project)))
|
||||
(write! cfg :project (str (:id project)) project)
|
||||
(vswap! bfc/*state* update :projects conj (:id project)))
|
||||
|
||||
(defn- write-file!
|
||||
[cfg file-id]
|
||||
(let [file (bfc/get-file cfg file-id :realize? true)
|
||||
thumbs (bfc/get-file-object-thumbnails cfg file-id)
|
||||
media (bfc/get-file-media cfg file)
|
||||
rels (bfc/get-files-rels cfg #{file-id})]
|
||||
|
||||
(events/tap :progress
|
||||
{:op :export
|
||||
:section :write-file
|
||||
:id file-id
|
||||
:name (:name file)})
|
||||
|
||||
(vswap! bfc/*state* (fn [state]
|
||||
(-> state
|
||||
(update :files conj file-id)
|
||||
(update :file-media-objects into bfc/xf-map-id media)
|
||||
(bfc/collect-storage-objects thumbs)
|
||||
(bfc/collect-storage-objects media))))
|
||||
|
||||
(write! cfg :file file-id file)
|
||||
(write! cfg :file-rels file-id rels)
|
||||
|
||||
(run! (partial write! cfg :file-media-object file-id) media)
|
||||
(run! (partial write! cfg :file-object-thumbnail file-id) thumbs)
|
||||
|
||||
(when-let [thumb (bfc/get-file-thumbnail cfg file)]
|
||||
(vswap! bfc/*state* bfc/collect-storage-objects [thumb])
|
||||
(write! cfg :file-thumbnail file-id thumb))
|
||||
|
||||
(l/trc :hint "write" :obj "file"
|
||||
:thumbnails (count thumbs)
|
||||
:rels (count rels)
|
||||
:media (count media))))
|
||||
|
||||
(defn- write-storage-object!
|
||||
[{:keys [::sto/storage] :as cfg} id]
|
||||
(let [sobj (sto/get-object storage id)
|
||||
data (with-open [input (sto/get-object-data storage sobj)]
|
||||
(io/read input))]
|
||||
|
||||
(l/trc :hint "write" :obj "storage-object" :id (str id) :size (:size sobj))
|
||||
(write! cfg :storage-object id (meta sobj) data)))
|
||||
|
||||
(defn- read-storage-object!
|
||||
[{:keys [::sto/storage ::bfc/timestamp] :as cfg} id]
|
||||
(let [mdata (d/update-when (read-obj cfg :storage-object id)
|
||||
:content-type bfc/normalize-content-type)
|
||||
data (read-blob cfg :storage-object id)
|
||||
;; NOTE: v2 bundles are legacy and no longer produced; the
|
||||
;; sanitizer call stays as defense in depth and is covered by
|
||||
;; the shared helper unit tests, with no dedicated v2
|
||||
;; import test.
|
||||
clean (when (bfc/svg-object? mdata)
|
||||
(bfc/sanitize-imported-svg mdata data))
|
||||
data (or (:bytes clean) data)
|
||||
hash (or (:hash clean) (sto/calculate-hash data))
|
||||
|
||||
content (-> (sto/content data)
|
||||
(sto/wrap-with-hash hash))
|
||||
|
||||
params (-> mdata
|
||||
(assoc ::sto/content content)
|
||||
(assoc ::sto/deduplicate? true)
|
||||
(assoc ::sto/touched-at timestamp))
|
||||
|
||||
sobject (sto/put-object! storage params)]
|
||||
|
||||
(vswap! bfc/*state* update :index assoc id (:id sobject))
|
||||
|
||||
(l/trc :hint "read" :obj "storage-object"
|
||||
:id (str id)
|
||||
:new-id (str (:id sobject))
|
||||
:size (:size sobject))))
|
||||
|
||||
(defn read-team!
|
||||
[{:keys [::db/conn ::bfc/timestamp] :as cfg} team-id]
|
||||
(l/trc :hint "read" :obj "team" :id (str team-id))
|
||||
|
||||
(let [team (read-obj cfg :team team-id)
|
||||
team (-> team
|
||||
(update :id bfc/lookup-index)
|
||||
(update :photo-id bfc/lookup-index)
|
||||
(assoc :created-at timestamp)
|
||||
(assoc :modified-at timestamp))]
|
||||
|
||||
(events/tap :progress
|
||||
{:op :import
|
||||
:section :read-team
|
||||
:id team-id
|
||||
:name (:name team)})
|
||||
|
||||
(db/insert! conn :team
|
||||
(update team :features db/encode-pgarray conn "text")
|
||||
::db/return-keys false)
|
||||
|
||||
(doseq [font (->> (read-seq cfg :team-font-variant)
|
||||
(filter #(= team-id (:team-id %))))]
|
||||
(let [font (-> font
|
||||
(update :id bfc/lookup-index)
|
||||
(update :team-id bfc/lookup-index)
|
||||
(update :woff1-file-id bfc/lookup-index)
|
||||
(update :woff2-file-id bfc/lookup-index)
|
||||
(update :ttf-file-id bfc/lookup-index)
|
||||
(update :otf-file-id bfc/lookup-index)
|
||||
(assoc :created-at timestamp)
|
||||
(assoc :modified-at timestamp))]
|
||||
(db/insert! conn :team-font-variant font
|
||||
::db/return-keys false)))
|
||||
|
||||
team))
|
||||
|
||||
(defn read-project!
|
||||
[{:keys [::db/conn ::bfc/timestamp] :as cfg} project-id]
|
||||
(l/trc :hint "read" :obj "project" :id (str project-id))
|
||||
|
||||
(let [project (read-obj cfg :project project-id)
|
||||
project (-> project
|
||||
(update :id bfc/lookup-index)
|
||||
(update :team-id bfc/lookup-index)
|
||||
(assoc :created-at timestamp)
|
||||
(assoc :modified-at timestamp))]
|
||||
|
||||
(events/tap :progress
|
||||
{:op :import
|
||||
:section :read-project
|
||||
:id project-id
|
||||
:name (:name project)})
|
||||
|
||||
(db/insert! conn :project project
|
||||
::db/return-keys false)))
|
||||
|
||||
(defn read-file!
|
||||
[{:keys [::db/conn ::bfc/timestamp] :as cfg} file-id]
|
||||
(l/trc :hint "read" :obj "file" :id (str file-id))
|
||||
|
||||
(let [file (-> (read-obj cfg :file file-id)
|
||||
(update :id bfc/lookup-index)
|
||||
(update :project-id bfc/lookup-index))
|
||||
file (bfc/process-file cfg file)]
|
||||
|
||||
(events/tap :progress
|
||||
{:op :import
|
||||
:section :read-file
|
||||
:id file-id
|
||||
:name (:name file)})
|
||||
|
||||
;; All features that are enabled and requires explicit migration are
|
||||
;; added to the state for a posterior migration step.
|
||||
(doseq [feature (-> (::bfc/features cfg)
|
||||
(set/difference cfeat/no-migration-features)
|
||||
(set/difference (:features file)))]
|
||||
(vswap! bfc/*state* update :pending-to-migrate (fnil conj []) [feature (:id file)]))
|
||||
|
||||
(bfc/save-file! cfg file ::db/return-keys false))
|
||||
|
||||
(doseq [thumbnail (read-seq cfg :file-object-thumbnail file-id)]
|
||||
(let [thumbnail (-> thumbnail
|
||||
(update :file-id bfc/lookup-index)
|
||||
(update :media-id bfc/lookup-index))
|
||||
file-id (:file-id thumbnail)
|
||||
|
||||
thumbnail (update thumbnail :object-id
|
||||
#(str/replace-first % #"^(.*?)/" (str file-id "/")))]
|
||||
|
||||
(db/insert! conn :file-tagged-object-thumbnail thumbnail
|
||||
{::db/return-keys false})))
|
||||
|
||||
;; NOTE: v2 packages are only produced and imported through the
|
||||
;; developer REPL (`app.srepl.binfile`), never through the product, so
|
||||
;; this path keeps inserting the relations as they come: unlike v1 and
|
||||
;; v3 it does not skip self-referencing or circular links (see
|
||||
;; `bfc/library-link-status`).
|
||||
(doseq [rel (read-obj cfg :file-rels file-id)]
|
||||
(let [rel (-> rel
|
||||
(update :file-id bfc/lookup-index)
|
||||
(update :library-file-id bfc/lookup-index))]
|
||||
(db/insert! conn :file-library-rel rel
|
||||
::db/return-keys false)
|
||||
(bfc/upsert-file-library-sync! conn (assoc rel :synced-at timestamp))))
|
||||
|
||||
(doseq [media (read-seq cfg :file-media-object file-id)]
|
||||
(let [media (-> media
|
||||
(update :id bfc/lookup-index)
|
||||
(update :file-id bfc/lookup-index)
|
||||
(update :media-id bfc/lookup-index)
|
||||
(update :thumbnail-id bfc/lookup-index))]
|
||||
(db/insert! conn :file-media-object media
|
||||
::db/return-keys false
|
||||
::sql/on-conflict-do-nothing true))))
|
||||
|
||||
(def ^:private empty-summary
|
||||
{:teams #{}
|
||||
:files #{}
|
||||
:projects #{}
|
||||
:file-media-objects #{}
|
||||
:team-font-variants #{}
|
||||
:storage-objects #{}})
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; PUBLIC API
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn export-team!
|
||||
[cfg team-id]
|
||||
(let [id (uuid/next)
|
||||
tp (ct/tpoint)
|
||||
cfg (create-database cfg)]
|
||||
|
||||
(l/inf :hint "start"
|
||||
:operation "export"
|
||||
:id (str id)
|
||||
:path (str (::path cfg)))
|
||||
|
||||
(try
|
||||
(db/tx-run! cfg (fn [cfg]
|
||||
(setup-schema! cfg)
|
||||
(binding [bfc/*state* (volatile! empty-summary)]
|
||||
(write-team! cfg team-id)
|
||||
|
||||
(run! (partial write-project! cfg)
|
||||
(bfc/get-team-projects cfg team-id))
|
||||
|
||||
(run! (partial write-file! cfg)
|
||||
(bfc/get-team-files-ids cfg team-id))
|
||||
|
||||
(run! (partial write-storage-object! cfg)
|
||||
(-> bfc/*state* deref :storage-objects))
|
||||
|
||||
(write! cfg :manifest "team-id" team-id)
|
||||
(write! cfg :manifest "objects" (deref bfc/*state*))
|
||||
|
||||
(::path cfg))))
|
||||
(finally
|
||||
(pu/close! (::db cfg))
|
||||
|
||||
(let [elapsed (tp)]
|
||||
(l/inf :hint "end"
|
||||
:operation "export"
|
||||
:id (str id)
|
||||
:elapsed (ct/format-duration elapsed)))))))
|
||||
|
||||
(defn import-team!
|
||||
[cfg path]
|
||||
(let [id (uuid/next)
|
||||
tp (ct/tpoint)
|
||||
|
||||
cfg (-> (create-database cfg path)
|
||||
(assoc ::bfc/timestamp (ct/now)))]
|
||||
|
||||
(l/inf :hint "start"
|
||||
:operation "import"
|
||||
:id (str id)
|
||||
:path (str (::path cfg)))
|
||||
|
||||
(try
|
||||
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||
(db/exec-one! conn ["SET idle_in_transaction_session_timeout = 0"])
|
||||
(db/exec-one! conn ["SET CONSTRAINTS ALL DEFERRED"])
|
||||
|
||||
(binding [bfc/*state* (volatile! {:index {}})]
|
||||
(let [objects (read-obj cfg :manifest "objects")]
|
||||
|
||||
;; We first process all storage objects, they have
|
||||
;; deduplication so we can't rely on simple reindex. This
|
||||
;; operation populates the index for all storage objects.
|
||||
(run! (partial read-storage-object! cfg) (:storage-objects objects))
|
||||
|
||||
;; Populate index with all the incoming objects
|
||||
(vswap! bfc/*state* update :index
|
||||
(fn [index]
|
||||
(-> index
|
||||
(bfc/update-index (:teams objects))
|
||||
(bfc/update-index (:projects objects))
|
||||
(bfc/update-index (:files objects))
|
||||
(bfc/update-index (:file-media-objects objects))
|
||||
(bfc/update-index (:team-font-variants objects)))))
|
||||
|
||||
(let [team-id (read-obj cfg :manifest "team-id")
|
||||
team (read-team! cfg team-id)
|
||||
features (cfeat/get-team-enabled-features cf/flags team)
|
||||
cfg (assoc cfg ::bfc/features features)]
|
||||
|
||||
(run! (partial read-project! cfg) (:projects objects))
|
||||
(run! (partial read-file! cfg) (:files objects))
|
||||
|
||||
;; (run-pending-migrations! cfg)
|
||||
|
||||
team)))))
|
||||
(finally
|
||||
(pu/close! (::db cfg))
|
||||
|
||||
(let [elapsed (tp)]
|
||||
(l/inf :hint "end"
|
||||
:operation "import"
|
||||
:id (str id)
|
||||
:elapsed (ct/format-duration elapsed)))))))
|
||||
@ -245,6 +245,12 @@
|
||||
[:database-readonly {:optional true} ::sm/boolean]
|
||||
[:database-min-pool-size {:optional true} ::sm/int]
|
||||
[:database-max-pool-size {:optional true} ::sm/int]
|
||||
;; pgjdbc prepared statement cache (see app.db). Size is in bytes and is
|
||||
;; converted to the whole MiB the driver accepts. Absent keys mean the
|
||||
;; driver defaults; see docs/technical-guide/configuration.md.
|
||||
[:database-prepared-statement-cache-threshold {:optional true} [::sm/int {:min -1}]]
|
||||
[:database-prepared-statement-cache-queries {:optional true} [::sm/int {:min 0}]]
|
||||
[:database-prepared-statement-cache-size {:optional true} [::sm/int {:min 0}]]
|
||||
|
||||
[:quotes-teams-per-profile {:optional true} ::sm/int]
|
||||
[:quotes-access-tokens-per-profile {:optional true} ::sm/int]
|
||||
|
||||
@ -57,7 +57,9 @@
|
||||
|
||||
(def ^:private schema:pool-options
|
||||
[:map {:title "pool-options"}
|
||||
[::connect-timeout {:optional true} ::sm/int]
|
||||
[::connection-timeout {:optional true} ::sm/int]
|
||||
[::idle-timeout {:optional true} ::sm/int]
|
||||
[::max-lifetime {:optional true} ::sm/int]
|
||||
[::max-size {:optional true} ::sm/int]
|
||||
[::min-size {:optional true} ::sm/int]
|
||||
[::name {:optional true} :keyword]
|
||||
@ -66,6 +68,17 @@
|
||||
[::username {:optional true} :string]
|
||||
[::validation-timeout {:optional true} ::sm/int]
|
||||
[::read-only {:optional true} ::sm/boolean]
|
||||
;; pgjdbc prepared statement cache. Absent keys mean the driver
|
||||
;; defaults; the size is in bytes and is converted to whole MiB for
|
||||
;; the driver (see create-datasource-config). The threshold is the
|
||||
;; executions before a statement is server-prepared: 0 stops
|
||||
;; server-side prepared statements (the cache of parsed queries stays
|
||||
;; in use) and -1 prepares from the first execution. Any other
|
||||
;; negative is a typo the driver would clamp to -1, so the schema
|
||||
;; rejects it.
|
||||
[::prepared-statement-cache-threshold {:optional true} [::sm/int {:min -1}]]
|
||||
[::prepared-statement-cache-queries {:optional true} [::sm/int {:min 0}]]
|
||||
[::prepared-statement-cache-size {:optional true} [::sm/int {:min 0}]]
|
||||
[::mtx/metrics ::mtx/metrics]])
|
||||
|
||||
(def defaults
|
||||
@ -94,7 +107,10 @@
|
||||
:credentials (and (contains? cfg ::username)
|
||||
(contains? cfg ::password))
|
||||
:min-size (::min-size cfg)
|
||||
:max-size (::max-size cfg))
|
||||
:max-size (::max-size cfg)
|
||||
:prepared-statement-cache-threshold (::prepared-statement-cache-threshold cfg)
|
||||
:prepared-statement-cache-queries (::prepared-statement-cache-queries cfg)
|
||||
:prepared-statement-cache-size (::prepared-statement-cache-size cfg))
|
||||
(create-pool cfg))))
|
||||
|
||||
(defmethod ig/halt-key! ::pool
|
||||
@ -113,6 +129,17 @@
|
||||
;; pairwise, when both are partitioned with the same bounds
|
||||
"SET enable_partitionwise_join = on;"))
|
||||
|
||||
;; pgjdbc reads dataSourceProperties through Properties.getProperty, which
|
||||
;; drops non-String values silently, so everything is passed as a string.
|
||||
;; preparedStatementCacheSizeMiB only accepts a whole-MiB integer: the
|
||||
;; configured size (bytes) is converted up, so any positive value keeps the
|
||||
;; cache enabled and 0 disables the cache. A query parameter of the same name
|
||||
;; in the URI wins over these properties: pgjdbc ignores the Properties value
|
||||
;; when the URL carries it.
|
||||
(defn- bytes->mib-ceil
|
||||
[bytes]
|
||||
(Math/ceilDiv (long bytes) (* 1024 1024)))
|
||||
|
||||
(defn- create-datasource-config
|
||||
[{:keys [::uri] :as cfg}]
|
||||
|
||||
@ -132,6 +159,13 @@
|
||||
(.setConnectionInitSql initsql)
|
||||
(.setInitializationFailTimeout -1))
|
||||
|
||||
(some->> (::prepared-statement-cache-threshold cfg) (str)
|
||||
(.addDataSourceProperty config "prepareThreshold"))
|
||||
(some->> (::prepared-statement-cache-queries cfg) (str)
|
||||
(.addDataSourceProperty config "preparedStatementCacheQueries"))
|
||||
(some->> (::prepared-statement-cache-size cfg) (bytes->mib-ceil) (str)
|
||||
(.addDataSourceProperty config "preparedStatementCacheSizeMiB"))
|
||||
|
||||
(->> (mtx/get-registry (::mtx/metrics cfg))
|
||||
(PrometheusMetricsTrackerFactory.)
|
||||
(.setMetricsTrackerFactory config))
|
||||
|
||||
@ -425,6 +425,9 @@
|
||||
::db/read-only (cf/get :database-readonly false)
|
||||
::db/min-size (cf/get :database-min-pool-size)
|
||||
::db/max-size (cf/get :database-max-pool-size)
|
||||
::db/prepared-statement-cache-threshold (cf/get :database-prepared-statement-cache-threshold)
|
||||
::db/prepared-statement-cache-queries (cf/get :database-prepared-statement-cache-queries)
|
||||
::db/prepared-statement-cache-size (cf/get :database-prepared-statement-cache-size)
|
||||
::mtx/metrics (ig/ref ::mtx/metrics)}
|
||||
|
||||
;; Default netty IO pool (shared between several services)
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.srepl.binfile
|
||||
(:require
|
||||
[app.binfile.v2 :as binfile.v2]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.srepl.helpers :as h]
|
||||
[app.system :as sys]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(defn export-team!
|
||||
[team-id]
|
||||
(let [team-id (h/parse-uuid team-id)]
|
||||
(binfile.v2/export-team! sys/system team-id)))
|
||||
|
||||
(defn import-team!
|
||||
[path & {:keys [owner rollback?] :or {rollback? true}}]
|
||||
(db/tx-run! (assoc sys/system ::db/rollback rollback?)
|
||||
(fn [cfg]
|
||||
(let [team (binfile.v2/import-team! cfg path)
|
||||
owner (cond
|
||||
(string? owner)
|
||||
(db/get* cfg :profile {:email (str/lower owner)})
|
||||
(uuid? owner)
|
||||
(db/get* cfg :profile {:id owner}))]
|
||||
|
||||
(when owner
|
||||
(db/insert! cfg :team-profile-rel
|
||||
{:id (uuid/next)
|
||||
:team-id (:id team)
|
||||
:profile-id (:id owner)
|
||||
:is-admin true
|
||||
:is-owner true
|
||||
:can-edit true}))
|
||||
|
||||
team))))
|
||||
@ -76,6 +76,23 @@
|
||||
:worker-default-parallelism 4)]
|
||||
(t/is (= 4 (cf/get :worker-default-parallelism 1))))))
|
||||
|
||||
(t/deftest prepared-statement-cache-keys
|
||||
(t/testing "negative sizes are rejected; the threshold takes -1 or non-negatives"
|
||||
(t/is (not (cf/validate-config (assoc cf/config :database-prepared-statement-cache-queries -1))))
|
||||
(t/is (not (cf/validate-config (assoc cf/config :database-prepared-statement-cache-size -1))))
|
||||
(t/is (not (cf/validate-config (assoc cf/config :database-prepared-statement-cache-threshold -2))))
|
||||
(t/is (cf/validate-config (assoc cf/config :database-prepared-statement-cache-threshold -1))))
|
||||
(t/testing "a -1 threshold survives the environment decoding and validation"
|
||||
(let [cfg (merge cf/config
|
||||
(cf/decode-config {:database-prepared-statement-cache-threshold "-1"}))]
|
||||
(t/is (= -1 (:database-prepared-statement-cache-threshold cfg)))
|
||||
(t/is (cf/validate-config cfg))))
|
||||
(t/testing "a decoded -2 threshold fails validation"
|
||||
(let [cfg (merge cf/config
|
||||
(cf/decode-config {:database-prepared-statement-cache-threshold "-2"}))]
|
||||
(t/is (= -2 (:database-prepared-statement-cache-threshold cfg)))
|
||||
(t/is (not (cf/validate-config cfg))))))
|
||||
|
||||
(t/deftest jobs-user-ttl
|
||||
(t/testing "the env value is decoded as a duration"
|
||||
(let [decoded (cf/decode-config {:jobs-user-ttl "72h"})]
|
||||
|
||||
@ -36,6 +36,113 @@
|
||||
(do (Thread/sleep 10)
|
||||
(recur (dec attempt)))))))
|
||||
|
||||
(t/deftest pool-passes-prepared-statement-cache-properties
|
||||
;; The driver reads dataSourceProperties through Properties.getProperty,
|
||||
;; which keeps only String values, so the wiring must set them as strings.
|
||||
;; Comparing the literals alone cannot catch a property the driver ignores,
|
||||
;; so the threshold cases also read it back from a real connection.
|
||||
(let [metrics (ig/init-key :app.metrics/metrics {:default {}})
|
||||
init-pool (fn [opts]
|
||||
(ig/init-key :app.db/pool
|
||||
(merge {:app.db/uri (java.net.URI. "postgresql://localhost/test")
|
||||
:app.metrics/metrics metrics
|
||||
:app.db/name :test-prepared-statement-cache}
|
||||
opts)))
|
||||
with-connection (fn [opts f]
|
||||
(let [ds (init-pool (merge {:app.db/uri (:database-uri th/config)
|
||||
:app.db/username (:database-username th/config)
|
||||
:app.db/password (:database-password th/config)}
|
||||
opts))]
|
||||
(try
|
||||
(with-open [conn (.getConnection ^HikariDataSource ds)]
|
||||
(f conn))
|
||||
(finally
|
||||
(.close ^HikariDataSource ds)))))
|
||||
prepare-threshold (fn [conn]
|
||||
(.getPrepareThreshold
|
||||
^org.postgresql.PGConnection
|
||||
(.unwrap conn org.postgresql.PGConnection)))]
|
||||
(t/testing "absent keys stay absent"
|
||||
(let [ds (init-pool {})]
|
||||
(t/is (empty? (.getDataSourceProperties ^HikariDataSource ds)))
|
||||
(.close ^HikariDataSource ds)))
|
||||
(t/testing "the driver defaults apply when no option is set"
|
||||
(with-connection {} (fn [conn] (t/is (= 5 (prepare-threshold conn))))))
|
||||
(t/testing "configured keys reach the driver as strings"
|
||||
(let [ds (init-pool {:app.db/prepared-statement-cache-threshold 1
|
||||
:app.db/prepared-statement-cache-queries 512
|
||||
:app.db/prepared-statement-cache-size 10485760})
|
||||
props (.getDataSourceProperties ^HikariDataSource ds)]
|
||||
(t/is (= "1" (.getProperty props "prepareThreshold")))
|
||||
(t/is (= "512" (.getProperty props "preparedStatementCacheQueries")))
|
||||
(t/is (= "10" (.getProperty props "preparedStatementCacheSizeMiB")))
|
||||
(.close ^HikariDataSource ds)))
|
||||
(t/testing "a configured threshold reaches the driver"
|
||||
(with-connection {:app.db/prepared-statement-cache-threshold 1}
|
||||
(fn [conn] (t/is (= 1 (prepare-threshold conn)))))
|
||||
(with-connection {:app.db/prepared-statement-cache-threshold 0}
|
||||
(fn [conn] (t/is (= 0 (prepare-threshold conn))))))
|
||||
(t/testing "a -1 threshold reaches the driver (forceBinary)"
|
||||
(let [ds (init-pool {:app.db/prepared-statement-cache-threshold -1})]
|
||||
(t/is (= "-1" (.getProperty (.getDataSourceProperties ^HikariDataSource ds)
|
||||
"prepareThreshold")))
|
||||
(.close ^HikariDataSource ds)))
|
||||
(t/testing "a zero threshold reaches the driver (server-side statements off)"
|
||||
(let [ds (init-pool {:app.db/prepared-statement-cache-threshold 0})]
|
||||
(t/is (= "0" (.getProperty (.getDataSourceProperties ^HikariDataSource ds)
|
||||
"prepareThreshold")))
|
||||
(.close ^HikariDataSource ds)))
|
||||
(t/testing "a positive sub-MiB size rounds up so the cache stays enabled"
|
||||
(let [ds (init-pool {:app.db/prepared-statement-cache-size 1})]
|
||||
(t/is (= "1" (.getProperty (.getDataSourceProperties ^HikariDataSource ds)
|
||||
"preparedStatementCacheSizeMiB")))
|
||||
(.close ^HikariDataSource ds)))
|
||||
(t/testing "the MiB ceiling rounds a byte over the boundary up"
|
||||
(let [ds (init-pool {:app.db/prepared-statement-cache-size 1048577})]
|
||||
(t/is (= "2" (.getProperty (.getDataSourceProperties ^HikariDataSource ds)
|
||||
"preparedStatementCacheSizeMiB")))
|
||||
(.close ^HikariDataSource ds)))
|
||||
(t/testing "the cache limits hold a closed statement in the server"
|
||||
;; A closed statement stays prepared in the server only while the
|
||||
;; driver's cache holds it, so counting it in pg_prepared_statements is
|
||||
;; what tells an accepted property from an effective one.
|
||||
(let [cached? (fn [opts]
|
||||
(with-connection
|
||||
(merge {:app.db/prepared-statement-cache-threshold 1} opts)
|
||||
(fn [conn]
|
||||
(dotimes [_ 2]
|
||||
(with-open [stmt (.prepareStatement ^Connection conn "SELECT ?::int AS cache_probe")]
|
||||
(.setInt stmt 1 1)
|
||||
(with-open [rs (.executeQuery stmt)] (.next rs))))
|
||||
(-> (db/exec-one! conn ["SELECT count(*) AS n FROM pg_prepared_statements
|
||||
WHERE statement LIKE '%AS cache_probe'"])
|
||||
:n
|
||||
pos?))))]
|
||||
(t/testing "a positive sub-MiB size keeps the cache enabled"
|
||||
(t/is (cached? {:app.db/prepared-statement-cache-size 1})))
|
||||
(t/testing "zero size disables the cache"
|
||||
(t/is (not (cached? {:app.db/prepared-statement-cache-size 0}))))
|
||||
(t/testing "zero queries disables the cache"
|
||||
(t/is (not (cached? {:app.db/prepared-statement-cache-queries 0}))))))))
|
||||
|
||||
(t/deftest pool-rejects-a-non-minus-one-negative-threshold
|
||||
;; The pool boundary mirrors app.config: -1 prepares from the first
|
||||
;; execution, 0 stops server-side prepared statements, and any other
|
||||
;; negative is a typo the driver would silently clamp to -1.
|
||||
(let [options {:app.db/uri (:database-uri th/config)
|
||||
:app.db/username (:database-username th/config)
|
||||
:app.db/password (:database-password th/config)
|
||||
:app.metrics/metrics (ig/init-key :app.metrics/metrics {:default {}})}]
|
||||
(t/testing "a -2 threshold fails the pool schema"
|
||||
(t/is (thrown? clojure.lang.ExceptionInfo
|
||||
(ig/assert-key :app.db/pool
|
||||
(assoc options :app.db/prepared-statement-cache-threshold -2)))))
|
||||
(t/testing "-1 and 0 pass the pool schema"
|
||||
(t/is (nil? (ig/assert-key :app.db/pool
|
||||
(assoc options :app.db/prepared-statement-cache-threshold -1))))
|
||||
(t/is (nil? (ig/assert-key :app.db/pool
|
||||
(assoc options :app.db/prepared-statement-cache-threshold 0)))))))
|
||||
|
||||
(t/deftest pool-requires-metrics
|
||||
;; Metrics is required by the pool schema: a pool wired without it
|
||||
;; fails at the boundary (AssertionError when asserts are enabled) or
|
||||
|
||||
@ -232,6 +232,7 @@
|
||||
:enable-inspect-styles
|
||||
:enable-feature-fdata-objects-map
|
||||
:enable-feature-render-wasm
|
||||
:enable-feature-text-editor-wasm-html-paste
|
||||
:enable-token-import-from-library
|
||||
:enable-render-switch
|
||||
:enable-render-wasm-info
|
||||
|
||||
@ -26,12 +26,10 @@
|
||||
(throw (ex-info hint {:type :wasm-error :code code :hint hint :fn fn-name} cause)))))
|
||||
|
||||
(defmacro call
|
||||
"A helper for calling a wasm function.
|
||||
Catches any exception thrown by the WASM function, reads the error code from
|
||||
WASM when available, and routes it based on the error type:
|
||||
- :wasm-non-blocking: call app.main.errors/on-error (eventually, shows a toast and logs the error)
|
||||
- :wasm-critical or unknown: throws an exception to be handled by the global error handler (eventually, shows the internal error page)
|
||||
Restores the stack pointer on failure, since a trap leaves its shadow-stack frames behind."
|
||||
"Calls the WASM function `name`. On failure, throws a `:wasm-error` whose
|
||||
`:code` comes from `error-code`, or `:wasm-critical` when WASM set none.
|
||||
Restores the stack pointer on failure, since a trap leaves its shadow-stack
|
||||
frames behind."
|
||||
[module name & params]
|
||||
(let [fn-sym (with-meta (gensym "fn-") {:tag 'function})
|
||||
module-sym (gensym "module")
|
||||
|
||||
@ -68,6 +68,42 @@ else
|
||||
export PENPOT_PUBLIC_PATH_DIRECTIVES=""
|
||||
fi
|
||||
|
||||
# nginx's `auto` starts one worker per CPU of the host, not of the container,
|
||||
# and each worker reserves the memory for all its connections at startup. A
|
||||
# container limited to a few CPUs on a large node can run out of memory before
|
||||
# serving a request, so size the workers from the CPUs the container can use
|
||||
# (its cpuset, and its CPU quota rounded up) when they are fewer than the host's.
|
||||
container_cpu_limit() {
|
||||
local quota="" period="" cpus
|
||||
cpus="$(nproc 2>/dev/null)" || return 1
|
||||
if [ -r /sys/fs/cgroup/cpu.max ]; then
|
||||
read -r quota period < /sys/fs/cgroup/cpu.max
|
||||
elif [ -r /sys/fs/cgroup/cpu/cpu.cfs_quota_us ]; then
|
||||
quota="$(< /sys/fs/cgroup/cpu/cpu.cfs_quota_us)"
|
||||
period="$(< /sys/fs/cgroup/cpu/cpu.cfs_period_us)"
|
||||
fi
|
||||
# "max" (cgroup v2) and -1 (cgroup v1) mean no quota, and 0 is not one.
|
||||
if [[ "$quota" =~ ^[1-9][0-9]*$ && "$period" =~ ^[1-9][0-9]*$ ]]; then
|
||||
quota=$(( (quota + period - 1) / period ))
|
||||
(( quota < cpus )) && cpus=$quota
|
||||
fi
|
||||
(( cpus < $(nproc --all) )) || return 1
|
||||
echo "$cpus"
|
||||
}
|
||||
|
||||
export PENPOT_HTTP_SERVER_WORKER_PROCESSES=${PENPOT_HTTP_SERVER_WORKER_PROCESSES:-$(container_cpu_limit || echo auto)}
|
||||
export PENPOT_HTTP_SERVER_WORKER_CONNECTIONS=${PENPOT_HTTP_SERVER_WORKER_CONNECTIONS:-65535}
|
||||
|
||||
if [[ ! "$PENPOT_HTTP_SERVER_WORKER_PROCESSES" =~ ^(auto|[1-9][0-9]*)$ ]]; then
|
||||
echo "penpot: invalid PENPOT_HTTP_SERVER_WORKER_PROCESSES '${PENPOT_HTTP_SERVER_WORKER_PROCESSES}'; expected auto or a positive integer" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "$PENPOT_HTTP_SERVER_WORKER_CONNECTIONS" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "penpot: invalid PENPOT_HTTP_SERVER_WORKER_CONNECTIONS '${PENPOT_HTTP_SERVER_WORKER_CONNECTIONS}'; expected a positive integer" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export PENPOT_BACKEND_URI=${PENPOT_BACKEND_URI:-http://penpot-backend:6060}
|
||||
export PENPOT_EXPORTER_URI=${PENPOT_EXPORTER_URI:-http://penpot-exporter:6061}
|
||||
export PENPOT_HTTP_SERVER_MAX_BODY_SIZE=${PENPOT_HTTP_SERVER_MAX_BODY_SIZE:-367001600} # Default to 350MiB
|
||||
@ -75,7 +111,7 @@ export PENPOT_IPV6_LISTEN_DIRECTIVE=${PENPOT_IPV6_LISTEN_DIRECTIVE:-"listen [::]
|
||||
if is_truthy "${PENPOT_DISABLE_IPV6_LISTEN:-}"; then
|
||||
export PENPOT_IPV6_LISTEN_DIRECTIVE=""
|
||||
fi
|
||||
envsubst "\$PENPOT_BACKEND_URI,\$PENPOT_EXPORTER_URI,\$PENPOT_HTTP_SERVER_MAX_BODY_SIZE,\$PENPOT_IPV6_LISTEN_DIRECTIVE,\$PENPOT_PUBLIC_PATH,\$PENPOT_PUBLIC_PATH_DIRECTIVES" \
|
||||
envsubst "\$PENPOT_HTTP_SERVER_WORKER_PROCESSES,\$PENPOT_HTTP_SERVER_WORKER_CONNECTIONS,\$PENPOT_BACKEND_URI,\$PENPOT_EXPORTER_URI,\$PENPOT_HTTP_SERVER_MAX_BODY_SIZE,\$PENPOT_IPV6_LISTEN_DIRECTIVE,\$PENPOT_PUBLIC_PATH,\$PENPOT_PUBLIC_PATH_DIRECTIVES" \
|
||||
< /tmp/nginx.conf.template > /etc/nginx/nginx.conf
|
||||
|
||||
if [[ " $PENPOT_FLAGS " != *" disable-admin-console "* ]]; then
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
worker_processes auto;
|
||||
worker_processes ${PENPOT_HTTP_SERVER_WORKER_PROCESSES};
|
||||
pid /tmp/nginx.pid;
|
||||
include /etc/nginx/overrides/main.d/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 65535;
|
||||
worker_connections ${PENPOT_HTTP_SERVER_WORKER_CONNECTIONS};
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
|
||||
@ -780,6 +780,33 @@ If the PostgreSQL server is shared with other applications, make sure
|
||||
`PENPOT_DATABASE_MAX_POOL_SIZE` plus the connections used by everything else stays below
|
||||
the server's `max_connections` (100 by default).
|
||||
|
||||
#### Prepared statement cache
|
||||
|
||||
__Since version 2.20.0__
|
||||
|
||||
The driver keeps two things per connection: a cache of parsed queries and, once a query
|
||||
runs enough times, a statement prepared in the server whose plan the server can reuse.
|
||||
Both are on by default; you only need these settings to tune them or to turn them off:
|
||||
|
||||
```bash
|
||||
# Backend
|
||||
PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_THRESHOLD: 5
|
||||
PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_QUERIES: 256
|
||||
PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_SIZE: 5242880
|
||||
```
|
||||
|
||||
The values above are the driver defaults. `PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_THRESHOLD`
|
||||
is how many times a query runs on a connection before the driver prepares it server-side:
|
||||
`-1` prepares it from the first execution and forces binary transfer, and `0` stops the
|
||||
driver from preparing statements in the server. The cache of parsed queries stays in use
|
||||
with the threshold at `0`: the connection caches up to
|
||||
`PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_QUERIES` queries, using at most
|
||||
`PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_SIZE` bytes per connection (the size is rounded
|
||||
up to whole MiB for the driver), and setting either of those two to `0` disables the
|
||||
cache. With 60 connections, the ceiling is 60 × the size. Leave a variable unset and the
|
||||
driver default applies. A parameter of the same name in `PENPOT_DATABASE_URI`, such as
|
||||
`?prepareThreshold=0`, takes precedence over these variables.
|
||||
|
||||
### Storage
|
||||
|
||||
Storage refers to storing the user uploaded different objects in Penpot (assets, file data,...).
|
||||
@ -1049,6 +1076,27 @@ PENPOT_INTERNAL_RESOLVER: 127.0.0.11
|
||||
names. Defaults to the nameservers found in `/etc/resolv.conf`. `127.0.0.11` is the
|
||||
embedded Docker DNS server; use the address of your own resolver on other setups.
|
||||
|
||||
### Nginx workers
|
||||
|
||||
The frontend container sizes its nginx workers from the CPUs it can use, its CPU quota or
|
||||
its cpuset, when they are fewer than the CPUs of the host. Otherwise it starts one worker
|
||||
per CPU of the host. Each worker reserves the memory for all its connections when it
|
||||
starts, so tune these if the frontend uses more memory than you expect:
|
||||
|
||||
```bash
|
||||
# Frontend
|
||||
PENPOT_HTTP_SERVER_WORKER_PROCESSES: 2
|
||||
PENPOT_HTTP_SERVER_WORKER_CONNECTIONS: 2048
|
||||
```
|
||||
|
||||
- `PENPOT_HTTP_SERVER_WORKER_PROCESSES`: Number of nginx worker processes, a positive
|
||||
integer or `auto` for one per host CPU. Defaults to the CPUs the container can use, with
|
||||
the quota rounded up, or `auto` when it has no limit.
|
||||
- `PENPOT_HTTP_SERVER_WORKER_CONNECTIONS`: Maximum simultaneous connections per worker,
|
||||
a positive integer. Defaults to `65535`, which takes about 30 MB of memory per worker.
|
||||
|
||||
The container refuses to start if either value is not valid.
|
||||
|
||||
## Other flags
|
||||
|
||||
There are other flags that are useful for a more customized Penpot experience. This section has the list of the flags meant
|
||||
|
||||
@ -21,7 +21,7 @@ The `.penpot` format (version 3) uses a ZIP container with JSON files for metada
|
||||
| Version | Description | Status |
|
||||
|---------|-------------|--------|
|
||||
| v1 | Custom binary format | Deprecated |
|
||||
| v2 | SQLite-based format | Never released (internal only) |
|
||||
| v2 | SQLite-based format | Removed (never released) |
|
||||
| v3 | ZIP + JSON format | **Current** |
|
||||
|
||||
## File Structure
|
||||
|
||||
@ -143,11 +143,15 @@
|
||||
(rx/of team-form-modal)
|
||||
|
||||
:else
|
||||
(let [pending-id (str (uuid/next))
|
||||
callback-url (dom/append-query-param (rt/get-current-href)
|
||||
:pending-action-id pending-id)]
|
||||
(->> (rp/cmd! :check-nitrate-sso {:team-id team-id
|
||||
:url callback-url})
|
||||
(let [pending-id (str (uuid/next))
|
||||
;; The callback travels as a query string; the token is
|
||||
;; kept in its own shape because `append-query-param`
|
||||
;; works on URLs.
|
||||
callback-query-string (-> (rt/get-current-token)
|
||||
(dom/append-query-param :pending-action-id pending-id)
|
||||
rt/token->query-string)]
|
||||
(->> (rp/cmd! :check-nitrate-sso {:team-id team-id
|
||||
:query-string callback-query-string})
|
||||
(rx/mapcat
|
||||
(fn [{:keys [authorized redirect-uri]}]
|
||||
(cond
|
||||
|
||||
@ -738,17 +738,41 @@
|
||||
(ex/print-throwable cause :prefix "Unexpected Error")
|
||||
(flash :cause cause :type :unhandled))))
|
||||
|
||||
(def recoverable-wasm-codes
|
||||
"WASM error codes that show a toast; any other code shows the error page."
|
||||
#{:non-blocking :wasm-reload-context-failure :viewer-canvas-failed})
|
||||
|
||||
(defmethod ptk/handle-error :wasm-error
|
||||
[error]
|
||||
(when-let [cause (::instance error)]
|
||||
(ex/print-throwable cause)
|
||||
(let [code (get error :code)]
|
||||
(cond
|
||||
(= code :panic)
|
||||
(st/emit! (rt/assign-exception error))
|
||||
(if (contains? recoverable-wasm-codes (:code error))
|
||||
(flash :type :handled :cause cause)
|
||||
(st/emit! (rt/assign-exception error)))))
|
||||
|
||||
:else
|
||||
(flash :type :handled :cause cause)))))
|
||||
(defn- handle-wasm-effect-error
|
||||
[cause]
|
||||
(let [{:keys [type code]} (ex-data cause)]
|
||||
(if (and (= type :wasm-error) (contains? recoverable-wasm-codes code))
|
||||
(on-error cause)
|
||||
(throw cause))))
|
||||
|
||||
(defn wrap-wasm-effect
|
||||
"Runs the React effect fn `f` and guards the cleanup fn it returns: a
|
||||
recoverable WASM error goes to `on-error`, any other error is rethrown."
|
||||
[f]
|
||||
(let [result (try
|
||||
(f)
|
||||
(catch :default cause
|
||||
(handle-wasm-effect-error cause)
|
||||
nil))]
|
||||
(if (fn? result)
|
||||
(fn []
|
||||
(try
|
||||
(result)
|
||||
(catch :default cause
|
||||
(handle-wasm-effect-error cause))))
|
||||
result)))
|
||||
|
||||
;; We receive a explicit authentication error; If the uri is for
|
||||
;; workspace, dashboard, viewer or settings, then assign the exception
|
||||
|
||||
16
frontend/src/app/main/ui/hooks/wasm_effect.clj
Normal file
16
frontend/src/app/main/ui/hooks/wasm_effect.clj
Normal file
@ -0,0 +1,16 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.main.ui.hooks.wasm-effect
|
||||
(:require
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defmacro with-wasm-effect
|
||||
"Like `mf/with-effect`, but a recoverable WASM error shows a toast
|
||||
instead of reaching the React error boundary."
|
||||
[deps & body]
|
||||
`(mf/with-effect ~deps
|
||||
(app.main.errors/wrap-wasm-effect (fn [] ~@body))))
|
||||
12
frontend/src/app/main/ui/hooks/wasm_effect.cljs
Normal file
12
frontend/src/app/main/ui/hooks/wasm_effect.cljs
Normal file
@ -0,0 +1,12 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.main.ui.hooks.wasm-effect
|
||||
"React effects that call WASM. Kept apart from `app.main.ui.hooks`:
|
||||
the renderer loads that namespace, so it cannot require `app.main.errors`."
|
||||
(:require-macros [app.main.ui.hooks.wasm-effect])
|
||||
(:require
|
||||
[app.main.errors]))
|
||||
@ -14,9 +14,11 @@
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.errors :as errors]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.css-cursors :as cur]
|
||||
[app.main.ui.hooks.wasm-effect :refer [with-wasm-effect]]
|
||||
[app.render-wasm.api :as wasm.api]
|
||||
[app.render-wasm.text-editor :as text-editor]
|
||||
[app.util.dom :as dom]
|
||||
@ -607,48 +609,48 @@
|
||||
(.removeEventListener node "beforeinput" on-before-input)))))
|
||||
|
||||
;; Focus contenteditable on mount
|
||||
(mf/use-effect
|
||||
(mf/deps contenteditable-ref)
|
||||
(fn []
|
||||
;; Group the whole editing session (edits, reflow resizes, finalize) into a single
|
||||
;; undo entry. Nested transactions (e.g. style shortcuts) are ref-counted and fold in.
|
||||
(st/emit! (dwu/start-undo-transaction shape-id :timeout nil))
|
||||
(when-let [node (mf/ref-val contenteditable-ref)]
|
||||
;; Focus and select all text on mount (this will trigger on-focus)
|
||||
(.focus node)
|
||||
(text-editor/text-editor-select-all)
|
||||
(wasm.api/request-render-preserving-target "text-editor-select-all-on-mount"))
|
||||
;; On unmount, finalize the editor content and then dispose the WASM editor.
|
||||
;; We finalize on unmount instead of relying on the browser blur event, because
|
||||
;; it was not being reliable (timing issues, Firefox issues…)
|
||||
(fn []
|
||||
(on-blur)
|
||||
(st/emit! dw/hide-context-menu
|
||||
(dwt/v3-stop-text-layout-preview shape-id)
|
||||
(dwu/commit-undo-transaction shape-id))
|
||||
(text-editor/text-editor-dispose)
|
||||
(wasm.api/request-render-preserving-target "text-editor-dispose"))))
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps)
|
||||
(fn []
|
||||
(let [timeout-id (atom nil)
|
||||
schedule-blink (fn schedule-blink []
|
||||
;; The caret only blinks for a collapsed cursor. With an active
|
||||
;; selection there is nothing to animate, so skip the repaint:
|
||||
;; re-compositing every interval would otherwise redraw the
|
||||
;; selection over and over (a visible flicker at high zoom).
|
||||
(when (and (text-editor/text-editor-has-focus?)
|
||||
(not (text-editor/text-editor-has-selection?)))
|
||||
;; Redraw only the caret (cached frame + overlay) instead of a
|
||||
;; full `request-render`, which flashes on zoomed-in views by
|
||||
;; kicking off a progressive tile-by-tile shape re-render.
|
||||
(wasm.api/render-text-editor-overlay!))
|
||||
(reset! timeout-id (js/setTimeout schedule-blink caret-blink-interval-ms)))]
|
||||
(schedule-blink)
|
||||
(with-wasm-effect [contenteditable-ref]
|
||||
;; Group the whole editing session (edits, reflow resizes, finalize) into a single
|
||||
;; undo entry. Nested transactions (e.g. style shortcuts) are ref-counted and fold in.
|
||||
(st/emit! (dwu/start-undo-transaction shape-id :timeout nil))
|
||||
(when-let [node (mf/ref-val contenteditable-ref)]
|
||||
;; Focus and select all text on mount (this will trigger on-focus)
|
||||
(.focus node)
|
||||
;; Guarded apart so a recoverable error still returns the cleanup below,
|
||||
;; which commits the undo transaction opened above.
|
||||
(errors/wrap-wasm-effect
|
||||
(fn []
|
||||
(when @timeout-id
|
||||
(js/clearTimeout @timeout-id))))))
|
||||
(text-editor/text-editor-select-all)
|
||||
(wasm.api/request-render-preserving-target "text-editor-select-all-on-mount"))))
|
||||
;; On unmount, finalize the editor content and then dispose the WASM editor.
|
||||
;; We finalize on unmount instead of relying on the browser blur event, because
|
||||
;; it was not being reliable (timing issues, Firefox issues…)
|
||||
(fn []
|
||||
(on-blur)
|
||||
(st/emit! dw/hide-context-menu
|
||||
(dwt/v3-stop-text-layout-preview shape-id)
|
||||
(dwu/commit-undo-transaction shape-id))
|
||||
(text-editor/text-editor-dispose)
|
||||
(wasm.api/request-render-preserving-target "text-editor-dispose")))
|
||||
|
||||
(with-wasm-effect []
|
||||
(let [timeout-id (atom nil)
|
||||
schedule-blink (fn schedule-blink []
|
||||
;; The caret only blinks for a collapsed cursor. With an active
|
||||
;; selection there is nothing to animate, so skip the repaint:
|
||||
;; re-compositing every interval would otherwise redraw the
|
||||
;; selection over and over (a visible flicker at high zoom).
|
||||
(when (and (text-editor/text-editor-has-focus?)
|
||||
(not (text-editor/text-editor-has-selection?)))
|
||||
;; Redraw only the caret (cached frame + overlay) instead of a
|
||||
;; full `request-render`, which flashes on zoomed-in views by
|
||||
;; kicking off a progressive tile-by-tile shape re-render.
|
||||
(wasm.api/render-text-editor-overlay!))
|
||||
(reset! timeout-id (js/setTimeout schedule-blink caret-blink-interval-ms)))]
|
||||
(schedule-blink)
|
||||
(fn []
|
||||
(when @timeout-id
|
||||
(js/clearTimeout @timeout-id)))))
|
||||
|
||||
;; Composition and input events
|
||||
[:g.text-editor {:clip-path (dm/fmt "url(#%)" clip-id)
|
||||
|
||||
@ -97,12 +97,14 @@
|
||||
(st/emit! (dwt/resize-text id width height)))))
|
||||
|
||||
(st/emit! (dwt/clean-text-modifier id))))
|
||||
;; Always clear the task and log measurement errors.
|
||||
(p/catch (fn [cause]
|
||||
(log/error :hint "Could not measure text shape"
|
||||
:shape-id id
|
||||
:cause cause)
|
||||
nil))))
|
||||
;; Log measurement errors and resolve to nil. The returned promise
|
||||
;; stays pending until the measurement settles, so callers keep the
|
||||
;; text mounted while it is measured.
|
||||
(p/merr (fn [cause]
|
||||
(log/error :hint "Could not measure text shape"
|
||||
:shape-id id
|
||||
:cause cause)
|
||||
(p/resolved nil)))))
|
||||
|
||||
(defn- update-text-modifier
|
||||
[{:keys [grow-type id] :as shape} node]
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
[app.main.ui.context :as ctx]
|
||||
[app.main.ui.flex-controls :as mfc]
|
||||
[app.main.ui.hooks :as ui-hooks]
|
||||
[app.main.ui.hooks.wasm-effect :refer [with-wasm-effect]]
|
||||
[app.main.ui.measurements :as msr]
|
||||
[app.main.ui.workspace.shapes.path.editor :refer [path-editor*]]
|
||||
[app.main.ui.workspace.shapes.text.editor :as editor-v1]
|
||||
@ -461,7 +462,7 @@
|
||||
;; canvas, even though we are not using `page-id` inside the hook.
|
||||
;; We think moving this out to a handler will make the render code
|
||||
;; harder to follow through.
|
||||
(mf/with-effect [page-id]
|
||||
(with-wasm-effect [page-id]
|
||||
(when-let [canvas (mf/ref-val canvas-ref)]
|
||||
(let [timeout-id-ref (volatile! nil)
|
||||
unmounted? (volatile! false)
|
||||
@ -510,7 +511,7 @@
|
||||
(js/clearTimeout timeout-id))
|
||||
(wasm.api/clear-canvas)))))
|
||||
|
||||
(mf/with-effect [show-text-editor? workspace-editor-state edition @canvas-init? @initialized?]
|
||||
(with-wasm-effect [show-text-editor? workspace-editor-state edition @canvas-init? @initialized?]
|
||||
(let [active-editor-state (get workspace-editor-state edition)]
|
||||
(when (and show-text-editor? active-editor-state @canvas-init? @initialized?)
|
||||
(let [content (-> active-editor-state
|
||||
@ -532,16 +533,16 @@
|
||||
(ts/raf (fn [_] (wasm.api/render-sync)))))]
|
||||
cancel)))
|
||||
|
||||
(mf/with-effect [vport]
|
||||
(with-wasm-effect [vport]
|
||||
(when (and @canvas-init? @initialized?)
|
||||
(wasm.api/resize-canvas! (mf/ref-val canvas-ref))
|
||||
(wasm.api/set-view-box zoom vbox)))
|
||||
|
||||
(mf/with-effect [@canvas-init? preview-blend]
|
||||
(with-wasm-effect [@canvas-init? preview-blend]
|
||||
(when (and @canvas-init? preview-blend)
|
||||
(wasm.api/request-render "with-effect")))
|
||||
|
||||
(mf/with-effect [@canvas-init? vern zoom vbox background]
|
||||
(with-wasm-effect [@canvas-init? vern zoom vbox background]
|
||||
(when @canvas-init?
|
||||
(if (not @initialized?)
|
||||
(do
|
||||
@ -574,27 +575,27 @@
|
||||
(wasm.api/clear-focus-mode)
|
||||
(wasm.api/set-focus-mode focus)))))
|
||||
|
||||
(mf/with-effect [background]
|
||||
(with-wasm-effect [background]
|
||||
(when (and @canvas-init? @initialized?)
|
||||
(wasm.api/set-canvas-background background)))
|
||||
|
||||
;; Grid overlay: `clear-grid` must run only when the overlay was shown and is now off
|
||||
;; (e.g. leave grid frame, or `page-transition?`). Do not call it on every
|
||||
;; `hover-top-frame-id` change while not hovering a grid frame.
|
||||
(mf/with-effect [@canvas-init? hover-grid?]
|
||||
(with-wasm-effect [@canvas-init? hover-grid?]
|
||||
(when @canvas-init?
|
||||
(when (and (not hover-grid?) (mf/ref-val prev-hover-grid-shown?-ref))
|
||||
(wasm.api/clear-grid))
|
||||
(mf/set-ref-val! prev-hover-grid-shown?-ref hover-grid?)))
|
||||
|
||||
(mf/with-effect [@canvas-init? has-grid? hover-grid?
|
||||
(if (and has-grid? hover-grid?) @hover-top-frame-id ::no-grid-hover-id)]
|
||||
(with-wasm-effect [@canvas-init? has-grid? hover-grid?
|
||||
(if (and has-grid? hover-grid?) @hover-top-frame-id ::no-grid-hover-id)]
|
||||
(when (and @canvas-init? hover-grid?)
|
||||
(wasm.api/show-grid @hover-top-frame-id)))
|
||||
|
||||
;; Rulers-wasm: push visibility / offsets / selection band into the
|
||||
;; render-wasm overlay (always active, no feature flag).
|
||||
(mf/with-effect [@canvas-init?]
|
||||
(with-wasm-effect [@canvas-init?]
|
||||
(when @canvas-init?
|
||||
(wasm.api/push-ruler-theme-colors!)
|
||||
(theme/add-color-scheme-listener!
|
||||
@ -605,7 +606,7 @@
|
||||
;; Text-editor-wasm: push the theme colors (selection background, caret)
|
||||
;; into the WASM text editor so the selection follows the design tokens per
|
||||
;; theme (purple on light, teal on dark) instead of a hardcoded default.
|
||||
(mf/with-effect [@canvas-init?]
|
||||
(with-wasm-effect [@canvas-init?]
|
||||
(when @canvas-init?
|
||||
(wasm.api/text-editor-apply-theme)
|
||||
(theme/add-color-scheme-listener!
|
||||
@ -620,37 +621,37 @@
|
||||
;; off a progressive tile-by-tile re-render that flashes) or a cached-atlas
|
||||
;; blit (whose scale-capped atlas flashes crisp->blurry on zoomed-in views,
|
||||
;; e.g. when the text editor opens at high zoom).
|
||||
(mf/with-effect [@canvas-init? frame-visible?]
|
||||
(with-wasm-effect [@canvas-init? frame-visible?]
|
||||
(when @canvas-init?
|
||||
(wasm.api/set-rulers-frame-visible! frame-visible?)
|
||||
(wasm.api/render-from-backbuffer!)))
|
||||
|
||||
(mf/with-effect [@canvas-init? show-rulers?]
|
||||
(with-wasm-effect [@canvas-init? show-rulers?]
|
||||
(when @canvas-init?
|
||||
(wasm.api/set-rulers-visible! show-rulers?)
|
||||
(wasm.api/render-from-backbuffer!)))
|
||||
|
||||
(mf/with-effect [@canvas-init? show-rulers? offset-x offset-y]
|
||||
(with-wasm-effect [@canvas-init? show-rulers? offset-x offset-y]
|
||||
(when (and @canvas-init? show-rulers?)
|
||||
(wasm.api/set-rulers-offsets! offset-x offset-y)))
|
||||
|
||||
(mf/with-effect [@canvas-init? show-rulers?
|
||||
(some-> ruler-selection :x) (some-> ruler-selection :y)
|
||||
(some-> ruler-selection :width) (some-> ruler-selection :height)]
|
||||
(with-wasm-effect [@canvas-init? show-rulers?
|
||||
(some-> ruler-selection :x) (some-> ruler-selection :y)
|
||||
(some-> ruler-selection :width) (some-> ruler-selection :height)]
|
||||
(when (and @canvas-init? show-rulers?)
|
||||
(wasm.api/set-rulers-selection! ruler-selection)
|
||||
(wasm.api/render-from-backbuffer!)))
|
||||
|
||||
;; Paint background + rulers instantly, before shapes finish loading. Runs
|
||||
;; after the ruler push effects so the WASM ruler state is already set.
|
||||
(mf/with-effect [@canvas-init? page-id]
|
||||
(with-wasm-effect [@canvas-init? page-id]
|
||||
(when @canvas-init?
|
||||
(wasm.api/render-ui-only)))
|
||||
|
||||
;; Ruler guides: push the WASM-visible guide set to the render engine.
|
||||
;; `wasm-guides` is also passed to the SVG overlay for index-based hit
|
||||
;; testing — it must stay in sync with what we serialize here.
|
||||
(mf/with-effect [@canvas-init? wasm-guides objects]
|
||||
(with-wasm-effect [@canvas-init? wasm-guides objects]
|
||||
(when @canvas-init?
|
||||
(wasm.api/set-guides wasm-guides objects)))
|
||||
|
||||
@ -663,7 +664,7 @@
|
||||
(hooks/setup-shortcuts path-editing? path-drawing? text-editing? grid-editing?)
|
||||
(hooks/setup-active-frames base-objects hover-ids selected active-frames zoom transform vbox)
|
||||
|
||||
(mf/with-effect [path-editing? edition @initialized?]
|
||||
(with-wasm-effect [path-editing? edition @initialized?]
|
||||
(when (and path-editing? edition @initialized?)
|
||||
(wselect/use-shape edition)
|
||||
(wasm.api/set-shape-hidden true)
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
[app.plugins.management :as management]
|
||||
[app.plugins.page :as page]
|
||||
[app.plugins.parser :as parser]
|
||||
[app.plugins.persist :as wpsp]
|
||||
[app.plugins.reflow :as wrfp]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.shape :as shape]
|
||||
@ -765,4 +766,9 @@
|
||||
:waitForLayoutUpdate
|
||||
(fn [timeout]
|
||||
;; Resolves once every shape with reflow work in flight has settled.
|
||||
(wrfp/wait-for-layout-update timeout))))
|
||||
(wrfp/wait-for-layout-update timeout))
|
||||
|
||||
:waitForSave
|
||||
(fn [timeout]
|
||||
;; Resolves once pending edits are saved (or there is nothing to save).
|
||||
(wpsp/wait-for-save timeout))))
|
||||
|
||||
130
frontend/src/app/plugins/persist.cljs
Normal file
130
frontend/src/app/plugins/persist.cljs
Normal file
@ -0,0 +1,130 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.plugins.persist
|
||||
"Promise adapter for the plugin `waitForSave` method. Owns timeout
|
||||
validation, the short commit→buffer intake race, force-flush, and the
|
||||
save-vs-rollback race; persistence itself lives in
|
||||
`app.main.data.persistence`."
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.main.data.persistence :as dps]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
;; Leaves room for the 30s layout wait and the code itself under the
|
||||
;; default MCP tool timeout (120s).
|
||||
(def ^:private default-timeout 60000)
|
||||
|
||||
;; Primary quiescence: how long to wait for commits to enter buffer/queue
|
||||
;; before treating empty persistence as "nothing to save". Not the 200ms
|
||||
;; pending-status debounce.
|
||||
(def ^:private intake-ms 100)
|
||||
|
||||
(defn- pending-work?
|
||||
"True when persistence still holds buffered or queued commits."
|
||||
[{:keys [buffer queue]}]
|
||||
(boolean (or (seq buffer) (seq queue))))
|
||||
|
||||
(defn- ->js-error
|
||||
"Turns a cljs/JS failure into a JS Error for Promise rejection, keeping
|
||||
the `ex-data` `:code` as the Error `code` property."
|
||||
[cause]
|
||||
(let [err (if (instance? js/Error cause)
|
||||
cause
|
||||
(js/Error. (or (ex-message cause) (str cause))))
|
||||
code (:code (ex-data cause))]
|
||||
(when (keyword? code)
|
||||
(obj/set! err "code" (name code)))
|
||||
err))
|
||||
|
||||
(def ^:private earlier-failure-message
|
||||
(dm/str "Changes could not be saved: the file has a failed save that "
|
||||
"stays until the file is reopened, so no change can be confirmed "
|
||||
"as saved. Reopen the file to resume saving."))
|
||||
|
||||
(def ^:private retrying-message
|
||||
(dm/str "Changes could not be saved yet: saves are failing and Penpot "
|
||||
"keeps retrying them. Try again later."))
|
||||
|
||||
(defn- earlier-failure
|
||||
"Rejection for a wait that starts while persistence is `:error`."
|
||||
[pstate]
|
||||
(if (dps/save-retrying? pstate)
|
||||
(ex-info retrying-message {:type :persistence :code :save-retrying})
|
||||
(ex-info earlier-failure-message
|
||||
{:type :persistence
|
||||
:code (get-in pstate [:error :code] :save-failed)})))
|
||||
|
||||
(defn- wait-intake
|
||||
"Races buffer/queue becoming non-empty against an intake deadline of
|
||||
`delay-ms` (capped by the caller to the wait timeout)."
|
||||
[delay-ms]
|
||||
(->> (rx/race (->> (rx/from-atom refs/persistence {:emit-current-value? true})
|
||||
(rx/filter pending-work?)
|
||||
(rx/take 1)
|
||||
(rx/map (constantly :pending)))
|
||||
(->> (rx/of :empty)
|
||||
(rx/delay delay-ms)))
|
||||
(rx/take 1)))
|
||||
|
||||
(defn- wait-save-or-rollback
|
||||
"Races a clean persist settle against rollback start or completion.
|
||||
Soft rejection emits `::rollback-rejected` before settle can publish
|
||||
empty `:saved`; `::rolled-back` may arrive later after a reload."
|
||||
[timeout-ms]
|
||||
(rx/race (->> (dps/wait-persisted-or-error timeout-ms)
|
||||
(rx/map (constantly :saved)))
|
||||
(->> st/stream
|
||||
(rx/filter (some-fn (ptk/type? ::dps/rollback-rejected)
|
||||
(ptk/type? ::dps/rolled-back)))
|
||||
(rx/take 1)
|
||||
(rx/mapcat (fn [_]
|
||||
(rx/throw (ex-info "Changes were rolled back"
|
||||
{:type :persistence :code :rolled-back})))))))
|
||||
|
||||
(defn wait-for-save
|
||||
"Returns a JS Promise that resolves once pending file changes are saved,
|
||||
or there is nothing to save after a short intake window.
|
||||
|
||||
Rejects when `timeout` is invalid, the save fails (also a failure from
|
||||
before the call: a terminal one stays until the file is reopened),
|
||||
changes are rolled back during the wait, or the deadline elapses. The
|
||||
Error `code` is `save-timeout`, `rolled-back`, `save-retrying` (an
|
||||
earlier failure Penpot keeps retrying), or the failure code
|
||||
(`save-failed` unless the backend gave a more specific one). A nil
|
||||
`timeout` uses `default-timeout`."
|
||||
([] (wait-for-save nil))
|
||||
([timeout]
|
||||
(js/Promise.
|
||||
(fn [resolve reject]
|
||||
(if-not (u/valid-timeout? timeout)
|
||||
(u/reject-not-valid reject :waitForSave timeout)
|
||||
(let [timeout-ms (or timeout default-timeout)
|
||||
delay-ms (js/Math.min intake-ms timeout-ms)]
|
||||
(->> (wait-intake delay-ms)
|
||||
(rx/mapcat
|
||||
(fn [_]
|
||||
(let [pstate @refs/persistence]
|
||||
(cond
|
||||
(= :error (:status pstate))
|
||||
(rx/throw (earlier-failure pstate))
|
||||
|
||||
(pending-work? pstate)
|
||||
(do
|
||||
(st/emit! ::dps/force-persist)
|
||||
(wait-save-or-rollback timeout-ms))
|
||||
|
||||
:else
|
||||
(rx/of :empty)))))
|
||||
(rx/take 1)
|
||||
(rx/subs!
|
||||
(fn [_] (resolve))
|
||||
(fn [cause] (reject (->js-error cause)))))))))))
|
||||
@ -9,35 +9,16 @@
|
||||
argument validation, the default deadline and the rejection shape; the
|
||||
workspace only reports when its pending work has drained."
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.reflow :as wrf]
|
||||
[app.plugins.utils :as u]
|
||||
[beicon.v2.core :as rx]))
|
||||
|
||||
;; Ceiling for callers that pass no timeout, so a pipeline that never drains
|
||||
;; its marks rejects the promise rather than leaving it unsettled.
|
||||
(def ^:private default-timeout 30000)
|
||||
|
||||
;; Largest value a signed 32-bit timer accepts.
|
||||
(def ^:private max-timeout 2147483647)
|
||||
|
||||
(defn- valid-timeout?
|
||||
"Checks that a plugin timeout fits a signed 32-bit timer."
|
||||
[value]
|
||||
(or (nil? value)
|
||||
(and (number? value)
|
||||
(pos? value)
|
||||
(<= value max-timeout)
|
||||
(js/Number.isFinite value))))
|
||||
|
||||
(defn- reject-invalid!
|
||||
[reject value]
|
||||
(let [msg (dm/str "[PENPOT PLUGIN] Value not valid: " value
|
||||
". Code: " :waitForLayoutUpdate)]
|
||||
(.error js/console msg)
|
||||
(reject (js/Error. msg))))
|
||||
|
||||
(defn shape-wait-ids
|
||||
"Ids a per-shape wait covers: the shape subtree, its ancestors, and the file
|
||||
its components sync from."
|
||||
@ -59,8 +40,8 @@
|
||||
([ids timeout]
|
||||
(js/Promise.
|
||||
(fn [resolve reject]
|
||||
(if-not (valid-timeout? timeout)
|
||||
(reject-invalid! reject timeout)
|
||||
(if-not (u/valid-timeout? timeout)
|
||||
(u/reject-not-valid reject :waitForLayoutUpdate timeout)
|
||||
;; Race the settle signal against the deadline; the loser is
|
||||
;; unsubscribed. `settled` replays on subscribe, so an already drained
|
||||
;; map wins even against a 1ms deadline.
|
||||
|
||||
@ -341,10 +341,24 @@
|
||||
(display-not-valid code value)))
|
||||
|
||||
(defn reject-not-valid
|
||||
"Rejects a promise with the standard invalid-value Error and logs it."
|
||||
[reject code value]
|
||||
(let [msg (dm/str "[PENPOT PLUGIN] Value not valid: " value ". Code: " code)]
|
||||
(.error js/console msg)
|
||||
(reject msg)))
|
||||
(reject (js/Error. msg))))
|
||||
|
||||
(def max-timeout
|
||||
"Largest value a signed 32-bit timer accepts."
|
||||
2147483647)
|
||||
|
||||
(defn valid-timeout?
|
||||
"Checks that a plugin timeout fits a signed 32-bit timer."
|
||||
[value]
|
||||
(or (nil? value)
|
||||
(and (number? value)
|
||||
(pos? value)
|
||||
(<= value max-timeout)
|
||||
(js/Number.isFinite value))))
|
||||
|
||||
(defn mixed-value
|
||||
[values]
|
||||
|
||||
@ -128,6 +128,14 @@
|
||||
:name name
|
||||
:suffix suffix})
|
||||
|
||||
(defn local-export-filename
|
||||
"A single export's `:name` already carries the suffix (added by the UI)."
|
||||
[kind entry export-name]
|
||||
(case kind
|
||||
:pdf-frames (str (or export-name "export") ".pdf")
|
||||
:single (wasm.exports/sanitize-filename (dissoc entry :suffix) #{})
|
||||
(str (or export-name "export") ".zip")))
|
||||
|
||||
(defn- run-local-export
|
||||
[{:keys [job-id kind exports objects background] export-name :name}]
|
||||
(let [exports (mapv export-entry exports)]
|
||||
@ -162,14 +170,7 @@
|
||||
|
||||
:else
|
||||
(let [entry (first exports)
|
||||
filename (case kind
|
||||
:pdf-frames
|
||||
(str (or export-name "export") ".pdf")
|
||||
|
||||
:single
|
||||
(wasm.exports/sanitize-filename entry #{})
|
||||
|
||||
(str (or export-name "export") ".zip"))
|
||||
filename (local-export-filename kind entry export-name)
|
||||
mtype (case kind
|
||||
:pdf-frames "application/pdf"
|
||||
:single (export-mtype (:type entry))
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
[app.main.repo :as rp]
|
||||
[app.main.router :as rt]
|
||||
[app.main.ui.dashboard.team :as dtui]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.session-state :as ss]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
@ -35,8 +34,8 @@
|
||||
(let [team-id "00000000-0000-4000-8000-000000000001"
|
||||
organization-id "00000000-0000-4000-8000-000000000002"
|
||||
profile-id "00000000-0000-4000-8000-000000000003"
|
||||
dashboard-url "https://penpot.example/#/dashboard-recent?team-id=current-team"
|
||||
callback-url (str dashboard-url "&pending-action-id=pending-id")
|
||||
route-token "?screen=dashboard-recent&team-id=current-team"
|
||||
callback-query "screen=dashboard-recent&team-id=current-team&pending-action-id=pending-id"
|
||||
team {:id team-id
|
||||
:organization {:id organization-id
|
||||
:name "Product"
|
||||
@ -54,8 +53,7 @@
|
||||
:check-nitrate-sso
|
||||
(rx/of {:authorized false
|
||||
:redirect-uri "https://sso.example.test/login"}))))
|
||||
rt/get-current-href (mock/stub (constantly dashboard-url))
|
||||
dom/append-query-param (mock/stub (fn [_url _key _value] callback-url))
|
||||
rt/get-current-token (mock/stub (constantly route-token))
|
||||
uuid/next (mock/stub (constantly "pending-id"))
|
||||
ss/save-pending-action! (mock/stub (fn [& args]
|
||||
(swap! saved-actions conj args)))
|
||||
@ -68,7 +66,7 @@
|
||||
:on-next #(swap! emitted conj %)))))
|
||||
|
||||
(t/is (= [[:get-teams nil]
|
||||
[:check-nitrate-sso {:team-id team-id :url callback-url}]]
|
||||
[:check-nitrate-sso {:team-id team-id :query-string callback-query}]]
|
||||
@requests))
|
||||
(t/is (= [["pending-id" {:type :create-team-in-organization
|
||||
:team-id team-id}]]
|
||||
@ -81,8 +79,8 @@
|
||||
(let [team-id "00000000-0000-4000-8000-000000000001"
|
||||
organization-id "00000000-0000-4000-8000-000000000002"
|
||||
profile-id "00000000-0000-4000-8000-000000000003"
|
||||
dashboard-url "https://penpot.example/#/dashboard-recent?team-id=current-team"
|
||||
callback-url (str dashboard-url "&pending-action-id=pending-id")
|
||||
route-token "?screen=dashboard-recent&team-id=current-team"
|
||||
callback-query "screen=dashboard-recent&team-id=current-team&pending-action-id=pending-id"
|
||||
team {:id team-id
|
||||
:organization {:id organization-id
|
||||
:name "Product"
|
||||
@ -97,8 +95,7 @@
|
||||
(case command
|
||||
:get-teams (rx/of [team])
|
||||
:check-nitrate-sso (rx/of {:authorized true}))))
|
||||
rt/get-current-href (mock/stub (constantly dashboard-url))
|
||||
dom/append-query-param (mock/stub (fn [_url _key _value] callback-url))
|
||||
rt/get-current-token (mock/stub (constantly route-token))
|
||||
uuid/next (mock/stub (constantly "pending-id"))
|
||||
modal/show (mock/stub (fn [& args] {:modal-show args}))}
|
||||
(await (async/observe
|
||||
@ -107,7 +104,7 @@
|
||||
nil)
|
||||
:on-next #(swap! emitted conj %)))))
|
||||
|
||||
(t/is (= [:check-nitrate-sso {:team-id team-id :url callback-url}]
|
||||
(t/is (= [:check-nitrate-sso {:team-id team-id :query-string callback-query}]
|
||||
(last @requests)))
|
||||
(t/is (= {:modal-show [:team-form {:organization-id organization-id
|
||||
:organization-name "Product"}]}
|
||||
|
||||
@ -1179,3 +1179,115 @@
|
||||
(map (comp ::ev/name deref) (report-events @events)))
|
||||
(str type " is reported as handled, not unhandled"))
|
||||
(t/is (= 2 (count @events)) (str type " must show one notification")))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; WASM errors
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defn- ^:async handle-wasm-error
|
||||
"Sends a `:wasm-error` with `code` through `on-error`. Resolves to the
|
||||
errors assigned to the error page and the events emitted."
|
||||
[code]
|
||||
(let [events (atom [])
|
||||
assigned (atom [])
|
||||
cause (ex-info "WASM Error" {:type :wasm-error :code code :hint "WASM Error"})]
|
||||
(await
|
||||
(mock/with-mocks*
|
||||
{st/emit! (mock/stub (fn [& emitted] (swap! events into emitted)))
|
||||
rt/get-current-href (constantly "https://penpot.example.com/#/workspace")
|
||||
rt/assign-exception (fn [error] (swap! assigned conj error) error)
|
||||
tm/schedule (mock/stub (fn [f] (f)))
|
||||
st/format-last-events (mock/stub (fn [& _] "(stub last events)"))}
|
||||
(errors/on-error cause)
|
||||
(await (async/settle))))
|
||||
{:assigned @assigned :events @events}))
|
||||
|
||||
(t/deftest ^:async non-recoverable-wasm-errors-show-the-error-page
|
||||
;; Scenario: a panic, a trap with no code and an unknown code.
|
||||
;; Proves: each shows the error page and no toast.
|
||||
(doseq [code [:panic :wasm-critical :unknown-code]]
|
||||
(errors/reset-report-governor!)
|
||||
(let [{:keys [assigned events]} (await (handle-wasm-error code))]
|
||||
(t/is (= [code] (map :code assigned))
|
||||
(str code " must show the error page"))
|
||||
(t/is (empty? (report-events events))
|
||||
(str code " must not show a toast")))))
|
||||
|
||||
(t/deftest ^:async recoverable-wasm-errors-show-a-toast
|
||||
;; Scenario: WASM errors with a recoverable code. Proves: each shows a
|
||||
;; handled report and a toast, and keeps the page.
|
||||
(doseq [code [:non-blocking :wasm-reload-context-failure :viewer-canvas-failed]]
|
||||
(errors/reset-report-governor!)
|
||||
(let [{:keys [assigned events]} (await (handle-wasm-error code))]
|
||||
(t/is (empty? assigned)
|
||||
(str code " must not show the error page"))
|
||||
(t/is (= ["handled-exception"]
|
||||
(map (comp ::ev/name deref) (report-events events)))
|
||||
(str code " must show a toast")))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; wrap-wasm-effect
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defn- wasm-error
|
||||
[code]
|
||||
(ex-info "WASM Error" {:type :wasm-error :code code}))
|
||||
|
||||
(defn- run-wasm-effect
|
||||
"Runs `f` through `wrap-wasm-effect` with `on-error` captured. Returns the
|
||||
effect result, or the thrown error under `:thrown`, and the errors handled."
|
||||
[f]
|
||||
(let [handled (atom [])]
|
||||
(with-redefs [errors/on-error (mock/stub #(swap! handled conj %))]
|
||||
(let [result (try
|
||||
{:value (errors/wrap-wasm-effect f)}
|
||||
(catch :default cause
|
||||
{:thrown cause}))]
|
||||
(assoc result :handled @handled)))))
|
||||
|
||||
(t/deftest wrap-wasm-effect-returns-the-effect-value
|
||||
(t/testing "an effect that does not throw keeps its return value"
|
||||
(let [{:keys [value handled]} (run-wasm-effect (constantly :done))]
|
||||
(t/is (= :done value))
|
||||
(t/is (empty? handled)))))
|
||||
|
||||
(t/deftest wrap-wasm-effect-keeps-the-cleanup
|
||||
(t/testing "a returned cleanup fn still runs the original cleanup"
|
||||
(let [cleaned (atom false)
|
||||
{:keys [value]} (run-wasm-effect (fn [] #(reset! cleaned true)))]
|
||||
(t/is (fn? value))
|
||||
(value)
|
||||
(t/is (true? @cleaned)))))
|
||||
|
||||
(t/deftest wrap-wasm-effect-handles-recoverable-errors
|
||||
(t/testing "a recoverable WASM error goes to on-error and is not rethrown"
|
||||
(doseq [code errors/recoverable-wasm-codes]
|
||||
(let [cause (wasm-error code)
|
||||
{:keys [value thrown handled]} (run-wasm-effect #(throw cause))]
|
||||
(t/is (nil? value) (str code))
|
||||
(t/is (nil? thrown) (str code " must not be rethrown"))
|
||||
(t/is (= [cause] handled) (str code " must go to on-error"))))))
|
||||
|
||||
(t/deftest wrap-wasm-effect-rethrows-other-errors
|
||||
(t/testing "critical WASM errors and other errors are rethrown unchanged"
|
||||
(doseq [cause [(wasm-error :panic)
|
||||
(wasm-error :wasm-critical)
|
||||
(ex-info "other" {:type :validation})
|
||||
(js/Error. "plain")]]
|
||||
(let [{:keys [thrown handled]} (run-wasm-effect #(throw cause))]
|
||||
(t/is (identical? cause thrown) (ex-message cause))
|
||||
(t/is (empty? handled) (str (ex-message cause) " must not go to on-error"))))))
|
||||
|
||||
(t/deftest wrap-wasm-effect-guards-the-cleanup
|
||||
(t/testing "a recoverable error in the cleanup goes to on-error"
|
||||
(let [cause (wasm-error :non-blocking)
|
||||
handled (atom [])
|
||||
cleanup (:value (run-wasm-effect (fn [] #(throw cause))))]
|
||||
(with-redefs [errors/on-error (mock/stub #(swap! handled conj %))]
|
||||
(cleanup))
|
||||
(t/is (= [cause] @handled))))
|
||||
|
||||
(t/testing "a critical error in the cleanup is rethrown"
|
||||
(let [cause (wasm-error :wasm-critical)
|
||||
cleanup (:value (run-wasm-effect (fn [] #(throw cause))))]
|
||||
(t/is (thrown? js/Error (cleanup))))))
|
||||
|
||||
@ -289,3 +289,9 @@
|
||||
message (plugins.utils/error-messages (sm/explain schema {:value ""}))]
|
||||
(t/is (= "Field value is invalid: Empty input" message))))
|
||||
|
||||
(t/deftest test-reject-not-valid-rejects-an-error
|
||||
;; Plugins read `.message` off the rejection, so it must be an Error.
|
||||
(let [rejected (atom nil)]
|
||||
(plugins.utils/reject-not-valid #(reset! rejected %) :someMethod "bad")
|
||||
(t/is (instance? js/Error @rejected))
|
||||
(t/is (str/includes? (.-message @rejected) "Code: :someMethod"))))
|
||||
|
||||
294
frontend/test/frontend_tests/plugins/wait_for_save_test.cljs
Normal file
294
frontend/test/frontend_tests/plugins/wait_for_save_test.cljs
Normal file
@ -0,0 +1,294 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns frontend-tests.plugins.wait-for-save-test
|
||||
"Contract tests for app.plugins.persist/wait-for-save (plugin waitForSave)."
|
||||
(:require
|
||||
[app.main.data.persistence :as dps]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.api :as api]
|
||||
[app.plugins.persist :as persist]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.async :as async]
|
||||
[frontend-tests.helpers.mock :as mock]
|
||||
[frontend-tests.helpers.persistence :as thp :refer [local-commit with-persistence]]
|
||||
[okulary.core :as l]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(defn- with-save-mocks
|
||||
"Redirects persistence refs and st/emit! onto the fixture store."
|
||||
[store body]
|
||||
(mock/with-mocks*
|
||||
{refs/persistence (l/derived :persistence store)
|
||||
st/state store
|
||||
st/stream (ptk/input-stream store)}
|
||||
(body)))
|
||||
|
||||
(defn- await-outcome
|
||||
"Resolves to {:ok value} or {:error err} for a JS promise."
|
||||
[p]
|
||||
(-> p
|
||||
(.then (fn [v] {:ok v}))
|
||||
(.catch (fn [e] {:error e}))))
|
||||
|
||||
(defn- error-code
|
||||
[outcome]
|
||||
(some-> (:error outcome) .-code))
|
||||
|
||||
(t/deftest ^:async empty-persistence-resolves-after-intake
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [requests store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(let [outcome (await (await-outcome (persist/wait-for-save 2000)))]
|
||||
(t/is (contains? outcome :ok)
|
||||
"empty buffer and queue resolve after intake")
|
||||
(t/is (empty? @requests)
|
||||
"nothing to save sends no update-file")))))))))
|
||||
|
||||
(t/deftest ^:async context-wait-for-save-resolves
|
||||
;; Goes through the plugin context proxy, the only way plugins reach it.
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(let [^js ctx (api/create-context "00000000-0000-0000-0000-000000000000")
|
||||
outcome (await (await-outcome (.waitForSave ctx 2000)))]
|
||||
(t/is (contains? outcome :ok)
|
||||
"context waitForSave resolves with nothing to save")))))))))
|
||||
|
||||
(t/deftest ^:async invalid-timeout-rejects
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(doseq [value [-1 0 ##NaN ##Inf 2147483648]]
|
||||
(let [outcome (await (await-outcome (persist/wait-for-save value)))]
|
||||
(t/is (instance? js/Error (:error outcome))
|
||||
(str value " rejects with an Error"))
|
||||
(t/is (re-find #"not valid.*waitForSave"
|
||||
(or (some-> (:error outcome) .-message) ""))))))))))))
|
||||
|
||||
(t/deftest ^:async terminal-error-rejects
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
;; Empty queue+buffer with :error is a terminal waiter release
|
||||
;; (see dps/terminal-status?).
|
||||
(swap! store assoc-in [:persistence :status] :error)
|
||||
(swap! store assoc-in [:persistence :error]
|
||||
{:type :persistence :code :save-permission-denied})
|
||||
(swap! store assoc-in [:persistence :queue] #queue [])
|
||||
(swap! store assoc-in [:persistence :buffer] [])
|
||||
(let [outcome (await (await-outcome (persist/wait-for-save 2000)))]
|
||||
(t/is (contains? outcome :error)
|
||||
"terminal :error rejects waitForSave")
|
||||
(t/is (re-find #"(?i)could not be saved.*reopen"
|
||||
(or (some-> (:error outcome) .-message) "")))
|
||||
(t/is (= "save-permission-denied" (error-code outcome))
|
||||
"the stored failure code is kept")))))))))
|
||||
|
||||
(t/deftest ^:async retrying-error-rejects-without-reopen
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
;; A transport failure the slow retry cycle keeps resending
|
||||
;; (dps/save-retrying?) recovers by itself: no reopen advice.
|
||||
(swap! store update :persistence assoc
|
||||
:status :error
|
||||
:error {:type :persistence :cause-type :network}
|
||||
:failing-since (js/Date.now))
|
||||
(let [outcome (await (await-outcome (persist/wait-for-save 2000)))
|
||||
message (or (some-> (:error outcome) .-message) "")]
|
||||
(t/is (contains? outcome :error))
|
||||
(t/is (= "save-retrying" (error-code outcome)))
|
||||
(t/is (re-find #"(?i)retrying" message))
|
||||
(t/is (not (re-find #"(?i)reopen" message)))))))))))
|
||||
|
||||
(t/deftest ^:async save-failure-during-wait-rejects
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id response requests store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(ptk/emit! store (local-commit file-id))
|
||||
(await (async/wait-for #(seq (get-in @store [:persistence :buffer]))
|
||||
"commit is buffered"))
|
||||
(let [p (persist/wait-for-save 5000)]
|
||||
(await (async/wait-for #(seq @requests)
|
||||
"force-persist flushed the buffer"))
|
||||
(rx/error! response (ex-info "rejected" {:type :validation :code :invalid-data}))
|
||||
(let [outcome (await (await-outcome p))]
|
||||
(t/is (contains? outcome :error)
|
||||
"a save that fails during the wait rejects")
|
||||
(t/is (re-find #"(?i)could not be saved"
|
||||
(or (some-> (:error outcome) .-message) "")))
|
||||
(t/is (= "invalid-data" (error-code outcome))
|
||||
"the backend failure code reaches err.code"))))))))))
|
||||
|
||||
(t/deftest ^:async rolled-back-during-wait-rejects
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id response store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(ptk/emit! store (local-commit file-id))
|
||||
(await (async/wait-for #(seq (get-in @store [:persistence :buffer]))
|
||||
"commit is buffered"))
|
||||
(let [p (persist/wait-for-save 5000)
|
||||
_ (js/setTimeout
|
||||
(fn []
|
||||
(ptk/emit! store
|
||||
(ptk/data-event ::dps/rolled-back
|
||||
{:file-ids #{file-id}
|
||||
:page-ids #{}
|
||||
:shape-ids #{}})))
|
||||
20)
|
||||
outcome (await (await-outcome p))]
|
||||
(t/is (contains? outcome :error)
|
||||
"rollback during wait rejects even if status later looks saved")
|
||||
(t/is (re-find #"(?i)roll"
|
||||
(or (some-> (:error outcome) .-message) "")))
|
||||
(t/is (= "rolled-back" (error-code outcome)))
|
||||
;; Keep the save path from hanging the fixture
|
||||
(when (seq (get-in @store [:persistence :queue]))
|
||||
(rx/push! response {:revn 1}))))))))))
|
||||
|
||||
(t/deftest ^:async buffer-race-waits-for-commit-not-stale-saved
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id response requests store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(t/is (empty? (get-in @store [:persistence :buffer])))
|
||||
(t/is (or (nil? (get-in @store [:persistence :status]))
|
||||
(= :saved (get-in @store [:persistence :status]))))
|
||||
;; Emit after starting the wait so a naive immediate empty
|
||||
;; :saved resolve would succeed before the commit buffers.
|
||||
(let [p (persist/wait-for-save 5000)]
|
||||
(js/setTimeout
|
||||
(fn [] (ptk/emit! store (local-commit file-id)))
|
||||
0)
|
||||
(await (async/wait-for #(seq @requests) "force-persist sent the edit"))
|
||||
(rx/push! response {:revn 1})
|
||||
(let [outcome (await (await-outcome p))]
|
||||
(t/is (contains? outcome :ok)
|
||||
"wait covers the late-buffered commit instead of stale empty :saved"))))))))))
|
||||
|
||||
(t/deftest ^:async pending-work-emits-force-persist
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id response requests store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(ptk/emit! store (local-commit file-id))
|
||||
(await (async/wait-for #(seq (get-in @store [:persistence :buffer]))
|
||||
"commit is buffered"))
|
||||
(let [p (persist/wait-for-save 5000)]
|
||||
(await (async/wait-for #(seq @requests) "force-persist flushed the buffer"))
|
||||
(rx/push! response {:revn 1})
|
||||
(let [outcome (await (await-outcome p))]
|
||||
(t/is (contains? outcome :ok)
|
||||
"pending work resolves once the save lands"))))))))))
|
||||
|
||||
(t/deftest ^:async pending-work-short-timeout-rejects
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(ptk/emit! store (local-commit file-id))
|
||||
(await (async/wait-for #(seq (get-in @store [:persistence :buffer]))
|
||||
"commit is buffered"))
|
||||
;; Never answer the save; the wait must time out.
|
||||
(let [outcome (await (await-outcome (persist/wait-for-save 30)))]
|
||||
(t/is (contains? outcome :error)
|
||||
"pending work with no save answer rejects on timeout")
|
||||
(t/is (re-find #"(?i)timed out|waiting"
|
||||
(or (some-> (:error outcome) .-message) "")))
|
||||
(t/is (= "save-timeout" (error-code outcome)))))))))))
|
||||
|
||||
(t/deftest ^:async empty-short-timeout-resolves
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
;; Timeout shorter than the default 100ms intake; must still
|
||||
;; resolve (capped intake), not reject as a timeout.
|
||||
(let [outcome (await (await-outcome (persist/wait-for-save 5)))]
|
||||
(t/is (contains? outcome :ok)
|
||||
"empty short timeout resolves (nothing to save)")))))))))
|
||||
|
||||
(t/deftest ^:async soft-rejection-during-wait-rejects
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id response requests store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(let [commit (local-commit file-id)]
|
||||
(ptk/emit! store commit)
|
||||
(await (async/wait-for #(seq (get-in @store [:persistence :buffer]))
|
||||
"commit is buffered"))
|
||||
(let [p (persist/wait-for-save 5000)]
|
||||
(await (async/wait-for #(seq @requests)
|
||||
"force-persist flushed the buffer"))
|
||||
(rx/push! response (thp/rejection (:id @commit)))
|
||||
(let [outcome (await (await-outcome p))]
|
||||
(t/is (contains? outcome :error)
|
||||
"soft rejection rejects wait-for-save, not success on later :saved")
|
||||
(t/is (re-find #"(?i)roll"
|
||||
(or (some-> (:error outcome) .-message) "")))
|
||||
(t/is (= "rolled-back" (error-code outcome)))))))))))))
|
||||
|
||||
(t/deftest ^:async rollback-rejected-beats-empty-saved
|
||||
(await
|
||||
(with-persistence
|
||||
(^:async fn [{:keys [file-id response requests store]}]
|
||||
(await
|
||||
(with-save-mocks store
|
||||
(^:async fn []
|
||||
(ptk/emit! store (local-commit file-id))
|
||||
(await (async/wait-for #(seq (get-in @store [:persistence :buffer]))
|
||||
"commit is buffered"))
|
||||
(let [p (persist/wait-for-save 5000)]
|
||||
(await (async/wait-for #(seq @requests)
|
||||
"force-persist flushed the buffer"))
|
||||
;; Rollback starts before settle can publish empty :saved;
|
||||
;; never emit ::rolled-back (reload-delay case).
|
||||
(ptk/emit! store (ptk/data-event ::dps/rollback-rejected {}))
|
||||
(swap! store assoc-in [:persistence :status] :saved)
|
||||
(swap! store assoc-in [:persistence :buffer] [])
|
||||
(swap! store assoc-in [:persistence :queue] #queue [])
|
||||
(let [outcome (await (await-outcome p))]
|
||||
(t/is (contains? outcome :error)
|
||||
"rollback-rejected rejects even when :saved would win the race")
|
||||
(t/is (re-find #"(?i)roll"
|
||||
(or (some-> (:error outcome) .-message) "")))
|
||||
(t/is (= "rolled-back" (error-code outcome)))
|
||||
(when (seq (get-in @store [:persistence :queue]))
|
||||
(rx/push! response {:revn 1})))))))))))
|
||||
@ -116,6 +116,7 @@
|
||||
[frontend-tests.plugins.user-test]
|
||||
[frontend-tests.plugins.utils-test]
|
||||
[frontend-tests.plugins.value-objects-test]
|
||||
[frontend-tests.plugins.wait-for-save-test]
|
||||
[frontend-tests.render-dimensions-test]
|
||||
[frontend-tests.render-wasm.call-test]
|
||||
[frontend-tests.render-wasm.modifiers-test]
|
||||
@ -189,6 +190,7 @@
|
||||
[frontend-tests.ui.subscription-test]
|
||||
[frontend-tests.ui.team-container-test]
|
||||
[frontend-tests.ui.text-attrs-multiple-test]
|
||||
[frontend-tests.ui.viewport-texts-html-test]
|
||||
[frontend-tests.ui.viewport-top-bar-test]
|
||||
[frontend-tests.ui.workspace-libraries-test]
|
||||
[frontend-tests.util-clipboard-test]
|
||||
@ -342,6 +344,7 @@
|
||||
'frontend-tests.plugins.user-test
|
||||
'frontend-tests.plugins.utils-test
|
||||
'frontend-tests.plugins.value-objects-test
|
||||
'frontend-tests.plugins.wait-for-save-test
|
||||
'frontend-tests.render-wasm.call-test
|
||||
'frontend-tests.render-wasm.modifiers-test
|
||||
'frontend-tests.render-wasm.process-objects-test
|
||||
@ -416,6 +419,7 @@
|
||||
'frontend-tests.ui.subscription-test
|
||||
'frontend-tests.ui.team-container-test
|
||||
'frontend-tests.ui.text-attrs-multiple-test
|
||||
'frontend-tests.ui.viewport-texts-html-test
|
||||
'frontend-tests.ui.viewport-top-bar-test
|
||||
'frontend-tests.ui.workspace-libraries-test
|
||||
'frontend-tests.util-clipboard-test
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns frontend-tests.ui.viewport-texts-html-test
|
||||
"How the SVG renderer measures text shapes and commits the result."
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.workspace.shapes.text.viewport-texts-html :as vth]
|
||||
[app.util.text-svg-position :as tsp]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.async :as async]
|
||||
[frontend-tests.helpers.mock :as mock]
|
||||
[potok.v2.core :as ptk]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(def ^:private fixed-text
|
||||
{:id (uuid/next) :type :text :grow-type :fixed})
|
||||
|
||||
(defn- measure-text
|
||||
"Measure `shape` as the SVG renderer does and return the measurement
|
||||
promise. Kept out of the `^:async` test bodies: there, a call through the
|
||||
var compiles to an awaited wrapper that would wait for the measurement."
|
||||
[shape]
|
||||
(#'vth/update-text-shape shape nil))
|
||||
|
||||
(defn- with-measurement
|
||||
"Run `f` with the text measurement mocked to `measurement`, a promise the
|
||||
test settles. Events emitted to the store are recorded in `emitted`."
|
||||
[measurement emitted f]
|
||||
(mock/with-mocks*
|
||||
{tsp/calc-position-data (mock/stub (constantly measurement))
|
||||
st/emit! (mock/stub (fn [& events] (swap! emitted into events) nil))}
|
||||
(await (f))))
|
||||
|
||||
(t/deftest ^:async measurement-promise-settles-with-the-measurement
|
||||
(let [measurement (p/deferred)
|
||||
emitted (atom [])
|
||||
settled? (atom false)]
|
||||
(await
|
||||
(with-measurement
|
||||
measurement
|
||||
emitted
|
||||
(^:async fn []
|
||||
(let [result (p/finally (measure-text fixed-text)
|
||||
#(reset! settled? true))]
|
||||
(await (async/settle))
|
||||
(t/is (false? @settled?)
|
||||
"the promise stays pending while the text is measured")
|
||||
(p/resolve measurement [])
|
||||
(await result)
|
||||
(t/is (true? @settled?)
|
||||
"the promise settles once the measurement settles")
|
||||
(t/is (some #(= ::dwt/clean-text-modifier (ptk/type %)) @emitted)
|
||||
"the measurement completes and cleans the text modifier")))))))
|
||||
|
||||
(t/deftest ^:async failed-measurement-resolves-to-nil
|
||||
(let [measurement (p/deferred)]
|
||||
(await
|
||||
(with-measurement
|
||||
measurement
|
||||
(atom [])
|
||||
(^:async fn []
|
||||
(let [result (measure-text fixed-text)]
|
||||
(p/reject measurement (ex-info "measure failed" {}))
|
||||
(t/is (nil? (await result))
|
||||
"a failed measurement resolves to nil")))))))
|
||||
@ -7,6 +7,7 @@
|
||||
(ns frontend-tests.worker.exports-test
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.worker.exports :as wexports]
|
||||
[app.worker.wasm :as wwasm]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
@ -48,6 +49,14 @@
|
||||
@order)
|
||||
"job B starts only after job A has finished")))
|
||||
|
||||
(t/deftest single-export-filename-does-not-repeat-suffix
|
||||
(t/is (= "Ellipseabc.svg"
|
||||
(wexports/local-export-filename
|
||||
:single {:name "Ellipseabc" :suffix "abc" :type :svg} nil)))
|
||||
(t/is (= "Ellipse.png"
|
||||
(wexports/local-export-filename
|
||||
:single {:name "Ellipse" :suffix nil :type :png} nil))))
|
||||
|
||||
(t/deftest cancel-job-is-visible-to-cancelled
|
||||
(let [job-id (uuid/next)]
|
||||
(t/is (false? (wwasm/cancelled? job-id)))
|
||||
|
||||
@ -295,9 +295,10 @@ The Penpot MCP server can be configured using environment variables.
|
||||
| `PENPOT_MCP_REPL_PORT` | Port for the REPL server (development/debugging) | `4403` |
|
||||
| `PENPOT_MCP_REPL_HOST` | Address on which the REPL server listens (binds to) | `localhost` |
|
||||
| `PENPOT_MCP_REPL_ENABLE` | Explicitly enable/disable the REPL server. Set to `true` to enable. When unset, defaults to the value of `PENPOT_MCP_DEVENV`. The REPL server never starts in multi-user mode. | (unset) |
|
||||
| `PENPOT_MCP_REMOTE_MODE` | Enable remote mode (disables file system access). Set to `true` to enable. | `false` |
|
||||
| `PENPOT_MCP_REMOTE_MODE` | Enable remote mode (disables file system access). Set to `true` to enable. In single-user mode it does not open the server to other hosts; see `PENPOT_MCP_ALLOWED_HOSTS`. | `false` |
|
||||
| `PENPOT_MCP_ALLOWED_HOSTS` | Comma-separated hostnames (no ports; IPv6 in brackets) that requests to the MCP endpoint, the plugin WebSocket and the REPL server may carry in their `Host` and `Origin` headers. Requests with any other hostname are rejected, which stops web pages from driving the server. Entries with a scheme, port or path stop the server from starting. When unset, single-user mode allows only `localhost`, `127.0.0.1` and `[::1]`, with or without remote mode, and multi-user mode allows any hostname. Set it when clients, the plugin or a proxy reach a single-user server under another name. Set it to `*` to turn the check off (not recommended in single-user mode: any web page you open can then drive the server). | (unset) |
|
||||
| `PENPOT_MCP_DEVENV` | Enable Penpot development environment tools in local single-user mode. Set to `true` to enable. | `false` |
|
||||
| `PENPOT_MCP_TOOL_TIMEOUT_S` | Timeout, in seconds, for tool calls dispatched to the Penpot plugin | `120` |
|
||||
| `PENPOT_MCP_TOOL_TIMEOUT_S` | Timeout, in seconds, for tool calls dispatched to the Penpot plugin. `execute_code` waits up to 30s for layout and 60s for the save, so keep it above 90s plus the code's run time | `120` |
|
||||
| `PENPOT_MCP_MAX_BODY_SIZE` | Maximum size of a JSON request body accepted by the MCP endpoint, in any format supported by Express (e.g. `10mb`) | `10mb` |
|
||||
| `PENPOT_MCP_EXPORT_SHAPE_MAX_PARALLEL_REQUESTS` | Maximum number of parallel export shape requests (multi-user mode only). | `0` (no limit) |
|
||||
| `PENPOT_MCP_AUTH_URI` | Public base URL of the MCP authorization service, e.g. `https://penpot.example/api/mcp/oauth`. Set to enable OAuth; requires `--multi-user`. Use HTTPS (HTTP is allowed on loopback for development), without credentials, query parameters, or a fragment. | (unset; OAuth disabled) |
|
||||
|
||||
193
mcp/packages/plugin/src/ExecuteCodeTaskHandler.test.ts
Normal file
193
mcp/packages/plugin/src/ExecuteCodeTaskHandler.test.ts
Normal file
@ -0,0 +1,193 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import { runInNewContext } from "node:vm";
|
||||
import ts from "typescript";
|
||||
import * as PenpotUtils from "./PenpotUtils.ts";
|
||||
import { ExecuteCodeTaskConsole } from "./ExecuteCodeTaskConsole.ts";
|
||||
|
||||
type TaskResponse = {
|
||||
type: string;
|
||||
response: {
|
||||
id: string;
|
||||
success: boolean;
|
||||
data?: unknown;
|
||||
error?: string;
|
||||
};
|
||||
};
|
||||
|
||||
/** Compiles a TypeScript source file for a simulated plugin context. */
|
||||
function compile(name: string) {
|
||||
return ts.transpileModule(readFileSync(new URL(name, import.meta.url), "utf8"), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads Task + ExecuteCodeTaskHandler with `penpot` / `penpotMgmt` resolved from
|
||||
* the outer globalThis (so installPenpot can configure them before construction).
|
||||
*/
|
||||
function loadHandler(): { ExecuteCodeTaskHandler: any; Task: any } {
|
||||
const taskExports: Record<string, unknown> = {};
|
||||
const handlerExports: Record<string, unknown> = {};
|
||||
|
||||
const context: Record<string, unknown> = {
|
||||
console,
|
||||
exports: taskExports,
|
||||
require: (id: string) => {
|
||||
if (id === "../TaskHandler" || id.endsWith("/TaskHandler")) {
|
||||
return taskExports;
|
||||
}
|
||||
if (id.includes("common/src")) {
|
||||
return {};
|
||||
}
|
||||
if (id.includes("PenpotUtils")) {
|
||||
return PenpotUtils;
|
||||
}
|
||||
if (id.includes("ExecuteCodeTaskConsole")) {
|
||||
return { ExecuteCodeTaskConsole };
|
||||
}
|
||||
throw new Error(`Unexpected import: ${id}`);
|
||||
},
|
||||
};
|
||||
Object.defineProperty(context, "penpot", {
|
||||
enumerable: true,
|
||||
get: () => (globalThis as any).penpot,
|
||||
});
|
||||
Object.defineProperty(context, "penpotMgmt", {
|
||||
enumerable: true,
|
||||
get: () => (globalThis as any).penpotMgmt,
|
||||
});
|
||||
|
||||
runInNewContext(compile("TaskHandler.ts"), context);
|
||||
|
||||
context.exports = handlerExports;
|
||||
runInNewContext(compile("task-handlers/ExecuteCodeTaskHandler.ts"), context);
|
||||
|
||||
return {
|
||||
ExecuteCodeTaskHandler: handlerExports.ExecuteCodeTaskHandler,
|
||||
Task: taskExports.Task,
|
||||
};
|
||||
}
|
||||
|
||||
function installPenpot(options: { waitForSave?: (() => Promise<void>) | null; workspaceStatus?: string }): {
|
||||
messages: TaskResponse[];
|
||||
} {
|
||||
const messages: TaskResponse[] = [];
|
||||
const penpot: Record<string, unknown> = {
|
||||
flags: {
|
||||
naturalChildOrdering: false,
|
||||
throwValidationErrors: false,
|
||||
},
|
||||
waitForLayoutUpdate: async () => undefined,
|
||||
ui: {
|
||||
sendMessage: (message: TaskResponse) => {
|
||||
messages.push(message);
|
||||
},
|
||||
},
|
||||
};
|
||||
if (options.waitForSave !== null && options.waitForSave !== undefined) {
|
||||
penpot.waitForSave = options.waitForSave;
|
||||
}
|
||||
(globalThis as any).penpot = penpot;
|
||||
(globalThis as any).penpotMgmt =
|
||||
options.workspaceStatus === undefined ? undefined : { workspace: { status: options.workspaceStatus } };
|
||||
return { messages };
|
||||
}
|
||||
|
||||
function lastResponse(messages: TaskResponse[]) {
|
||||
assert.ok(messages.length > 0, "expected a task response");
|
||||
return messages[messages.length - 1].response;
|
||||
}
|
||||
|
||||
test("awaits waitForSave before reporting success", async () => {
|
||||
let resolveSave!: () => void;
|
||||
let waitForSaveCalls = 0;
|
||||
const saveGate = new Promise<void>((resolve) => {
|
||||
resolveSave = resolve;
|
||||
});
|
||||
const { messages } = installPenpot({
|
||||
waitForSave: async () => {
|
||||
waitForSaveCalls += 1;
|
||||
return saveGate;
|
||||
},
|
||||
});
|
||||
|
||||
const { ExecuteCodeTaskHandler, Task } = loadHandler();
|
||||
const handler = new ExecuteCodeTaskHandler();
|
||||
const task = new Task("req-1", "executeCode", { code: "return 42;" });
|
||||
const done = handler.handle(task);
|
||||
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
assert.equal(messages.length, 0, "must not succeed before save settles");
|
||||
assert.equal(waitForSaveCalls, 1, "must call waitForSave after the code runs");
|
||||
|
||||
resolveSave();
|
||||
await done;
|
||||
|
||||
const response = lastResponse(messages);
|
||||
assert.equal(response.success, true);
|
||||
assert.equal((response.data as any).result, 42);
|
||||
});
|
||||
|
||||
test("reports an error when waitForSave rejects", async () => {
|
||||
const { messages } = installPenpot({
|
||||
waitForSave: async () => {
|
||||
throw new Error("Changes could not be saved");
|
||||
},
|
||||
});
|
||||
|
||||
const { ExecuteCodeTaskHandler, Task } = loadHandler();
|
||||
const handler = new ExecuteCodeTaskHandler();
|
||||
const task = new Task("req-2", "executeCode", { code: "return 1;" });
|
||||
await assert.rejects(handler.handle(task), /could not be saved/i);
|
||||
assert.equal(messages.length, 0, "must not report success");
|
||||
});
|
||||
|
||||
test("hard-fails when waitForSave is missing", async () => {
|
||||
const { messages } = installPenpot({ waitForSave: null });
|
||||
|
||||
const { ExecuteCodeTaskHandler, Task } = loadHandler();
|
||||
const handler = new ExecuteCodeTaskHandler();
|
||||
const task = new Task("req-3", "executeCode", { code: "return 1;" });
|
||||
await assert.rejects(handler.handle(task), /waitForSave/);
|
||||
assert.equal(messages.length, 0, "must not report success");
|
||||
});
|
||||
|
||||
for (const workspaceStatus of ["none", "loading"]) {
|
||||
test(`skips waitForSave when the workspace is ${workspaceStatus}`, async () => {
|
||||
let waitForSaveCalls = 0;
|
||||
const { messages } = installPenpot({
|
||||
workspaceStatus,
|
||||
waitForSave: async () => {
|
||||
waitForSaveCalls += 1;
|
||||
throw new Error("Changes could not be saved");
|
||||
},
|
||||
});
|
||||
|
||||
const { ExecuteCodeTaskHandler, Task } = loadHandler();
|
||||
const handler = new ExecuteCodeTaskHandler();
|
||||
const task = new Task("req-4", "executeCode", { code: "return 7;" });
|
||||
await handler.handle(task);
|
||||
|
||||
assert.equal(waitForSaveCalls, 0, "no workspace edit can be pending");
|
||||
const response = lastResponse(messages);
|
||||
assert.equal(response.success, true);
|
||||
assert.equal((response.data as any).result, 7);
|
||||
});
|
||||
}
|
||||
|
||||
test("awaits waitForSave when the workspace is ready", async () => {
|
||||
const { messages } = installPenpot({
|
||||
workspaceStatus: "ready",
|
||||
waitForSave: async () => {
|
||||
throw new Error("Changes could not be saved");
|
||||
},
|
||||
});
|
||||
|
||||
const { ExecuteCodeTaskHandler, Task } = loadHandler();
|
||||
const handler = new ExecuteCodeTaskHandler();
|
||||
const task = new Task("req-5", "executeCode", { code: "return 1;" });
|
||||
await assert.rejects(handler.handle(task), /could not be saved/i);
|
||||
assert.equal(messages.length, 0, "must not report success");
|
||||
});
|
||||
@ -1,8 +1,9 @@
|
||||
/**
|
||||
* WebSocket close code the MCP server uses for policy violations.
|
||||
*
|
||||
* The server rejects a second plugin connection for the same user token, and
|
||||
* connections missing a token in multi-user mode, with this code.
|
||||
* The server rejects a second plugin connection for the same user token,
|
||||
* connections missing a token in multi-user mode, and connections whose `Host`
|
||||
* or `Origin` is not allowed, with this code.
|
||||
*/
|
||||
export const WS_CLOSE_POLICY_VIOLATION = 1008;
|
||||
|
||||
|
||||
@ -44,28 +44,34 @@ export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
|
||||
// set the flags naturalChildOrdering and throwValidationErrors to true during code execution.
|
||||
let originalNaturalChildOrdering: any, originalThrowValidationErrors: any;
|
||||
if (penpot.flags) {
|
||||
originalNaturalChildOrdering = penpot.flags.naturalChildOrdering;
|
||||
penpot.flags.naturalChildOrdering = true;
|
||||
originalThrowValidationErrors = penpot.flags.throwValidationErrors;
|
||||
penpot.flags.throwValidationErrors = true;
|
||||
} else {
|
||||
if (!penpot.flags || typeof penpot.waitForSave !== "function") {
|
||||
throw new Error(
|
||||
"You are using a version of the Penpot MCP server which is incompatible " +
|
||||
"with the connected Penpot version. " +
|
||||
"The connected Penpot build is missing Plugin API support that this MCP " +
|
||||
"plugin needs (for example `penpot.waitForSave`), or the MCP plugin is " +
|
||||
"too new for that Penpot. Upgrade Penpot (and its plugins-runtime) so " +
|
||||
"they match this MCP version. " +
|
||||
"Read the documentation for instructions on which version to use: " +
|
||||
"https://github.com/penpot/penpot/tree/develop/mcp\n" +
|
||||
"If you are an LLM, tell the user about this!"
|
||||
);
|
||||
}
|
||||
|
||||
originalNaturalChildOrdering = penpot.flags.naturalChildOrdering;
|
||||
penpot.flags.naturalChildOrdering = true;
|
||||
originalThrowValidationErrors = penpot.flags.throwValidationErrors;
|
||||
penpot.flags.throwValidationErrors = true;
|
||||
|
||||
// Layout and save waits only apply with a ready workspace: on the dashboard (or while a file
|
||||
// loads) no edit of this call can be pending. Checked at each wait, since the code may navigate.
|
||||
const management = this.context.penpotMgmt;
|
||||
const workspaceReady = () => !management || management.workspace.status === "ready";
|
||||
|
||||
let result: any;
|
||||
try {
|
||||
// wait for layout updates prior to executing the supplied code (if method is available)
|
||||
try {
|
||||
const management = this.context.penpotMgmt;
|
||||
// @ts-ignore - TODO Penpot.waitForLayoutUpdate is not yet in the released types
|
||||
if ((!management || management.workspace.status === "ready") && penpot.waitForLayoutUpdate) {
|
||||
if (workspaceReady() && penpot.waitForLayoutUpdate) {
|
||||
// @ts-ignore
|
||||
await penpot.waitForLayoutUpdate();
|
||||
}
|
||||
@ -93,6 +99,11 @@ export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
result = ExecuteCodeTaskHandler.encodeBytesAsBase64Envelope(result);
|
||||
}
|
||||
|
||||
// Wait for the save outside any swallow catch: a failed or rolled-back save must fail the task.
|
||||
if (workspaceReady()) {
|
||||
await penpot.waitForSave();
|
||||
}
|
||||
|
||||
// return result and captured log
|
||||
let resultData: ExecuteCodeTaskResultData<any> = {
|
||||
result: result,
|
||||
|
||||
@ -87,6 +87,7 @@ Penpot:
|
||||
flatten(shapes: Shape[]): Path[];
|
||||
createVariantFromComponents(shapes: Board[]): VariantContainer;
|
||||
waitForLayoutUpdate(timeout?: number): Promise<void>;
|
||||
waitForSave(timeout?: number): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
@ -354,6 +355,7 @@ Penpot:
|
||||
* themechange: event emitted when the user changes its theme. The callback will receive the new theme (currently: either `dark` or `light`)
|
||||
* filechange: event emitted when a different file is opened. The callback will receive the new file.
|
||||
* contentsave: event emitted after the file content is saved in the backend. The callback receives no arguments.
|
||||
* contentrollback: event emitted after the backend rejected some changes and they were undone in the workspace. The callback receives a `ContentRollback` with the files, pages and shapes affected.
|
||||
* finish: event emitted when the current file is closed. The callback will receive the id of the closed file.
|
||||
|
||||
Type Parameters
|
||||
@ -1041,6 +1043,33 @@ Penpot:
|
||||
|
||||
The promise to be resolved when the layout is updated. It is
|
||||
rejected with an Error, both on timeout and on an invalid timeout value.
|
||||
waitForSave: |-
|
||||
```
|
||||
waitForSave(timeout?: number): Promise<void>
|
||||
```
|
||||
|
||||
This method returns a promise that will be resolved when pending file
|
||||
changes have been saved to the backend, or when there is nothing to save.
|
||||
It force-flushes the persistence buffer first when work is pending.
|
||||
|
||||
Parameters
|
||||
|
||||
* timeout: number
|
||||
|
||||
Maximum time to wait, in milliseconds. If the timeout
|
||||
elapses before the save settles, the promise is rejected. Defaults to
|
||||
60000; the promise never waits indefinitely.
|
||||
|
||||
Returns Promise<void>
|
||||
|
||||
The promise to be resolved when the save has settled. It is
|
||||
rejected with an Error on save failure, when changes are rolled back
|
||||
during the wait, on timeout, or on an invalid timeout value. A save
|
||||
that failed before the call also rejects: with `save-retrying` while
|
||||
Penpot keeps retrying it, otherwise with the failure code until the
|
||||
file is reopened. The Error `code` property tells the cases apart:
|
||||
`save-timeout`, `rolled-back`, `save-retrying`, or the failure code
|
||||
(`save-failed` unless the backend gave a more specific one).
|
||||
ActiveUser:
|
||||
overview: |-
|
||||
Interface ActiveUser
|
||||
@ -5365,7 +5394,8 @@ Team:
|
||||
|
||||
Example
|
||||
```
|
||||
const [team] = await penpotMgmt.listTeams();const projects = await team.listProjects();
|
||||
const [team] = await penpotMgmt.listTeams();
|
||||
const projects = await team.listProjects();
|
||||
```
|
||||
listDeletedProjects: |-
|
||||
```
|
||||
@ -5519,7 +5549,8 @@ Project:
|
||||
|
||||
Example
|
||||
```
|
||||
const file = await project.createFile({ name: 'Login' });await file.open();
|
||||
const file = await project.createFile({ name: 'Login' });
|
||||
await file.open();
|
||||
```
|
||||
duplicate: |-
|
||||
```
|
||||
@ -5585,7 +5616,7 @@ ProjectFile:
|
||||
}
|
||||
```
|
||||
|
||||
Referenced by: PenpotMgmt, Project, ProjectFile
|
||||
Referenced by: PenpotMgmt, Project, ProjectFile, Team
|
||||
members:
|
||||
Properties:
|
||||
id: |-
|
||||
@ -5814,7 +5845,8 @@ PenpotMgmt:
|
||||
|
||||
Example
|
||||
```
|
||||
const file = await penpotMgmt.getFile(penpotMgmt.workspace.fileId!);file.name = 'Checkout';
|
||||
const file = await penpotMgmt.getFile(penpotMgmt.workspace.fileId!);
|
||||
file.name = 'Checkout';
|
||||
```
|
||||
openFile: |-
|
||||
```
|
||||
@ -5940,6 +5972,7 @@ Context:
|
||||
flatten(shapes: Shape[]): Path[];
|
||||
createVariantFromComponents(shapes: Board[]): VariantContainer;
|
||||
waitForLayoutUpdate(timeout?: number): Promise<void>;
|
||||
waitForSave(timeout?: number): Promise<void>;
|
||||
}
|
||||
```
|
||||
members:
|
||||
@ -6793,6 +6826,33 @@ Context:
|
||||
|
||||
The promise to be resolved when the layout is updated. It is
|
||||
rejected with an Error, both on timeout and on an invalid timeout value.
|
||||
waitForSave: |-
|
||||
```
|
||||
waitForSave(timeout?: number): Promise<void>
|
||||
```
|
||||
|
||||
This method returns a promise that will be resolved when pending file
|
||||
changes have been saved to the backend, or when there is nothing to save.
|
||||
It force-flushes the persistence buffer first when work is pending.
|
||||
|
||||
Parameters
|
||||
|
||||
* timeout: number
|
||||
|
||||
Maximum time to wait, in milliseconds. If the timeout
|
||||
elapses before the save settles, the promise is rejected. Defaults to
|
||||
60000; the promise never waits indefinitely.
|
||||
|
||||
Returns Promise<void>
|
||||
|
||||
The promise to be resolved when the save has settled. It is
|
||||
rejected with an Error on save failure, when changes are rolled back
|
||||
during the wait, on timeout, or on an invalid timeout value. A save
|
||||
that failed before the call also rejects: with `save-retrying` while
|
||||
Penpot keeps retrying it, otherwise with the failure code until the
|
||||
file is reopened. The Error `code` property tells the cases apart:
|
||||
`save-timeout`, `rolled-back`, `save-retrying`, or the failure code
|
||||
(`save-failed` unless the backend gave a more specific one).
|
||||
ContextGeometryUtils:
|
||||
overview: |-
|
||||
Interface ContextGeometryUtils
|
||||
@ -8162,6 +8222,7 @@ EventsMap:
|
||||
finish: string;
|
||||
shapechange: Shape;
|
||||
contentsave: void;
|
||||
contentrollback: ContentRollback;
|
||||
}
|
||||
```
|
||||
|
||||
@ -8222,6 +8283,56 @@ EventsMap:
|
||||
```
|
||||
|
||||
The `contentsave` event will trigger after the file content is saved in the backend.
|
||||
contentrollback: |-
|
||||
```
|
||||
readonly contentrollback: ContentRollback
|
||||
```
|
||||
|
||||
The `contentrollback` event will trigger after the backend rejected some changes
|
||||
and the workspace undid them, together with the rest of their undo steps and any
|
||||
later change to the same file. Changes made by a plugin can be undone this way
|
||||
after the call that made them returned, so a plugin that relies on them should
|
||||
read the affected shapes again. The event fires once the undone data is in the
|
||||
workspace. When the workspace could not undo the changes in place, it reloads the
|
||||
file from the server first; the whole file then holds the server data, so shapes
|
||||
outside the listed ones may have changed too.
|
||||
ContentRollback:
|
||||
overview: |-
|
||||
Interface ContentRollback
|
||||
=========================
|
||||
|
||||
What a rollback of rejected changes undid, as given to the `contentrollback` event.
|
||||
|
||||
```
|
||||
interface ContentRollback {
|
||||
fileIds: string[];
|
||||
pageIds: string[];
|
||||
shapeIds: string[];
|
||||
}
|
||||
```
|
||||
|
||||
Referenced by: EventsMap
|
||||
members:
|
||||
Properties:
|
||||
fileIds: |-
|
||||
```
|
||||
readonly fileIds: string[]
|
||||
```
|
||||
|
||||
Ids of the files that lost changes.
|
||||
pageIds: |-
|
||||
```
|
||||
readonly pageIds: string[]
|
||||
```
|
||||
|
||||
Ids of the pages the undone changes touched.
|
||||
shapeIds: |-
|
||||
```
|
||||
readonly shapeIds: string[]
|
||||
```
|
||||
|
||||
Ids of the page shapes the undone changes touched. A shape the undone changes
|
||||
created no longer exists; one they removed exists again.
|
||||
Export:
|
||||
overview: |-
|
||||
Interface Export
|
||||
|
||||
@ -25,13 +25,21 @@ before trying to observe changes.
|
||||
To wait only for a single shape (and its children), use `await shape.waitForLayoutUpdate();`.
|
||||
Both accept an optional timeout in milliseconds (default 30000) and reject when it elapses.
|
||||
Every `execute_code` call waits for updates before applying your code, so you never need to call `waitForLayoutUpdate` at the beginning of your code.
|
||||
Every `execute_code` call also waits for pending changes to be saved before it returns success, so you should not call
|
||||
`await penpot.waitForSave()` at the end of your code (that would wait twice).
|
||||
That automatic save wait defaults to 60s and runs after the automatic layout wait (default 30s); both, plus your code,
|
||||
must fit inside the MCP tool timeout (`PENPOT_MCP_TOOL_TIMEOUT_S`, default 120s). If layout or saves are slow and tools
|
||||
time out before a save error appears, raise that env var.
|
||||
|
||||
## Rejected Changes and Read-Only Mode
|
||||
|
||||
Penpot saves your changes to the backend after your `execute_code` call returns.
|
||||
When the backend rejects a save, Penpot undoes the rejected changes, together with the rest of their undo steps
|
||||
and any later change to the same file. This can happen a few seconds after the call that made the changes succeeded.
|
||||
The next tool response then starts with a warning that names the files, pages and shapes involved.
|
||||
`execute_code` only reports success after Penpot has saved the changes from that call (or confirmed there was nothing
|
||||
to save). If the save fails, times out, or the backend rejects the changes and the workspace rolls them back, the tool
|
||||
call fails with an error — do not treat a failed call as if the design was updated.
|
||||
A timeout while saves are still retrying means the save was not confirmed; it does not mean the file is fine.
|
||||
|
||||
When a rollback is reported only on a later tool response (rare: concurrent edits, or a race after a timed-out response),
|
||||
that response starts with a warning that names the files, pages and shapes involved.
|
||||
When you get this warning:
|
||||
* Do not trust what you know about the design from before: shapes you created may be gone, and removed ones may be back.
|
||||
* Read the affected pages and shapes again (e.g. `penpotUtils.shapeStructure(page.root, 3)`) and check that they hold what you expect.
|
||||
@ -39,6 +47,11 @@ When you get this warning:
|
||||
|
||||
While saves are failing, the workspace becomes read-only: every write through the API throws an error saying that the
|
||||
workspace is read-only because changes cannot be saved. Do not retry in a loop; wait and try again later, or tell the user.
|
||||
Once a save has failed for good, every `execute_code` call in that file fails with "Changes could not be saved", reads
|
||||
included, until the file is reopened. Tell the user to reopen the file. If the error says Penpot keeps retrying the
|
||||
saves, wait and try again later instead. Calls made from the dashboard do not wait for saves.
|
||||
A save failure does not undo `penpotMgmt` calls (projects, files, teams) made in the same code: read that state back
|
||||
before retrying them.
|
||||
Writes also throw when the user cannot edit the file, a version is being previewed or the canvas stopped rendering;
|
||||
the error says which. These do not pass by waiting: tell the user.
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { request as httpRequest } from "node:http";
|
||||
import { afterEach, beforeEach, test } from "node:test";
|
||||
import { type CallToolResult, Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
||||
import { PenpotMcpServer } from "./PenpotMcpServer";
|
||||
@ -173,6 +174,72 @@ test("OAuth challenges missing credentials and accepts bearer and query tokens",
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Posts an MCP initialize request with the given extra headers and returns the response status.
|
||||
*
|
||||
* Uses `node:http`, since `fetch` does not let the caller set the `Host` header.
|
||||
*/
|
||||
function initializeStatus(headers: Record<string, string>): Promise<number> {
|
||||
const body = JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method: "initialize",
|
||||
params: {
|
||||
protocolVersion: "2025-06-18",
|
||||
capabilities: {},
|
||||
clientInfo: { name: "guard-test", version: "1" },
|
||||
},
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = httpRequest(
|
||||
`${baseUrl}/mcp`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json, text/event-stream",
|
||||
...headers,
|
||||
},
|
||||
},
|
||||
(res) => {
|
||||
res.resume();
|
||||
resolve(res.statusCode!);
|
||||
}
|
||||
);
|
||||
req.on("error", reject);
|
||||
req.end(body);
|
||||
});
|
||||
}
|
||||
|
||||
for (const remoteMode of [undefined, "true"]) {
|
||||
test(`single-user mode rejects requests from foreign hosts and origins (remote mode: ${remoteMode})`, async () => {
|
||||
await server.stop();
|
||||
if (remoteMode === undefined) {
|
||||
delete process.env.PENPOT_MCP_REMOTE_MODE;
|
||||
} else {
|
||||
process.env.PENPOT_MCP_REMOTE_MODE = remoteMode;
|
||||
}
|
||||
delete process.env.PENPOT_MCP_ALLOWED_HOSTS;
|
||||
server = new PenpotMcpServer(false);
|
||||
await server.start();
|
||||
|
||||
assert.equal(await initializeStatus({ Host: `attacker.example:${server.port}` }), 403);
|
||||
assert.equal(
|
||||
await initializeStatus({ Host: `localhost:${server.port}`, Origin: "https://attacker.example" }),
|
||||
403
|
||||
);
|
||||
assert.equal(await initializeStatus({ Host: `localhost:${server.port}` }), 200);
|
||||
assert.equal(
|
||||
await initializeStatus({ Host: `127.0.0.1:${server.port}`, Origin: "http://localhost:4400" }),
|
||||
200
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test("multi-user mode accepts requests from any host by default", async () => {
|
||||
assert.equal(await initializeStatus({ Host: `penpot.example.com`, Origin: "https://penpot.example.com" }), 200);
|
||||
});
|
||||
|
||||
/**
|
||||
* Makes the plugin bridge answer each dispatched task at once with the given responses, in order.
|
||||
*/
|
||||
|
||||
@ -25,6 +25,7 @@ import { NreplClient } from "./NreplClient";
|
||||
import { ReplServer } from "./ReplServer";
|
||||
import { ApiDocs } from "./ApiDocs";
|
||||
import { McpAuthentication } from "./McpAuthentication";
|
||||
import { RequestGuard } from "./RequestGuard";
|
||||
|
||||
/**
|
||||
* Session context for request-scoped data.
|
||||
@ -115,6 +116,11 @@ export class PenpotMcpServer {
|
||||
private httpServer?: HttpServer;
|
||||
private readonly mcpHandler: McpHttpHandler;
|
||||
private readonly authentication: McpAuthentication;
|
||||
|
||||
/**
|
||||
* Check of the `Host` and `Origin` headers of HTTP and plugin WebSocket requests.
|
||||
*/
|
||||
public readonly requestGuard: RequestGuard;
|
||||
public readonly pluginBridge: PluginBridge;
|
||||
private readonly replServer: ReplServer | null;
|
||||
private apiDocs: ApiDocs;
|
||||
@ -167,6 +173,8 @@ export class PenpotMcpServer {
|
||||
this.maxBodySize = process.env.PENPOT_MCP_MAX_BODY_SIZE ?? "10mb";
|
||||
const toolTimeoutSecs = parseInt(process.env.PENPOT_MCP_TOOL_TIMEOUT_S ?? "120", 10);
|
||||
|
||||
this.requestGuard = RequestGuard.fromEnvironment(process.env, this.isMultiUserMode());
|
||||
|
||||
this.configLoader = new ConfigurationLoader(process.cwd());
|
||||
this.apiDocs = new ApiDocs();
|
||||
|
||||
@ -190,7 +198,7 @@ export class PenpotMcpServer {
|
||||
this.pluginBridge = new PluginBridge(this, this.webSocketPort, toolTimeoutSecs, this.redisBridge);
|
||||
|
||||
if (shouldStartReplServer(PenpotMcpServer.isReplEnabled(process.env), this.isMultiUserMode())) {
|
||||
this.replServer = new ReplServer(this.pluginBridge, this.replPort, this.replHost);
|
||||
this.replServer = new ReplServer(this.pluginBridge, this.requestGuard, this.replPort, this.replHost);
|
||||
} else {
|
||||
this.replServer = null;
|
||||
}
|
||||
@ -332,6 +340,7 @@ export class PenpotMcpServer {
|
||||
async start(): Promise<void> {
|
||||
const { default: express } = await import("express");
|
||||
this.app = express();
|
||||
this.app.use(this.requestGuard.httpMiddleware);
|
||||
this.app.use(express.json({ limit: this.maxBodySize }));
|
||||
|
||||
this.setupHttpEndpoints();
|
||||
@ -345,6 +354,13 @@ export class PenpotMcpServer {
|
||||
);
|
||||
this.logger.info(`Remote mode: ${this.isRemoteMode()}`);
|
||||
this.logger.info(`DevEnv mode: ${this.isDevEnv()}`);
|
||||
this.logger.info(`Allowed hosts and origins: ${this.requestGuard.describe()}`);
|
||||
if (this.requestGuard.allowsAny() && !this.isMultiUserMode()) {
|
||||
this.logger.warn(
|
||||
"Host and Origin check is off and no user token is required: " +
|
||||
"any web page opened in a browser that reaches this server can drive it"
|
||||
);
|
||||
}
|
||||
this.logger.info(`Modern Streamable HTTP endpoint: http://${this.host}:${this.port}/mcp`);
|
||||
this.logger.info(`WebSocket server URL: ws://${this.host}:${this.webSocketPort}`);
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import { WebSocket } from "ws";
|
||||
import { HEARTBEAT_REQUEST_INTERVAL_MS, PluginBridge } from "./PluginBridge";
|
||||
import { PluginTask } from "./PluginTask";
|
||||
import type { PenpotMcpServer } from "./PenpotMcpServer";
|
||||
import { RequestGuard } from "./RequestGuard";
|
||||
|
||||
let bridge: PluginBridge;
|
||||
let port = 17_600;
|
||||
@ -22,6 +23,7 @@ beforeEach(() => {
|
||||
host: "127.0.0.1",
|
||||
isMultiUserMode: () => multiUser,
|
||||
getSessionContext: () => ({ userToken }),
|
||||
requestGuard: RequestGuard.allowing(["localhost", "127.0.0.1"]),
|
||||
} as PenpotMcpServer,
|
||||
port,
|
||||
1
|
||||
@ -203,3 +205,34 @@ test("a task fails at once when its plugin connection closes before answering",
|
||||
// well within the 1s task timeout of these tests
|
||||
assert.ok(Date.now() - started < 500);
|
||||
});
|
||||
|
||||
test("closes a WebSocket opened by a page on a foreign site with a policy violation", async () => {
|
||||
const socket = new WebSocket(`ws://127.0.0.1:${port}?userToken=alice`, {
|
||||
headers: { Origin: "http://attacker.example" },
|
||||
});
|
||||
sockets.push(socket);
|
||||
const [code] = await once(socket, "close", { signal: AbortSignal.timeout(1500) });
|
||||
assert.equal(code, 1008);
|
||||
assert.equal(bridge.getUserConnections("alice"), undefined);
|
||||
});
|
||||
|
||||
test("closes a WebSocket that reaches the server under a foreign host name", async () => {
|
||||
const socket = new WebSocket(`ws://127.0.0.1:${port}?userToken=alice`, {
|
||||
headers: { Host: `attacker.example:${port}` },
|
||||
});
|
||||
sockets.push(socket);
|
||||
const [code] = await once(socket, "close", { signal: AbortSignal.timeout(1500) });
|
||||
assert.equal(code, 1008);
|
||||
});
|
||||
|
||||
test("accepts a WebSocket opened by a plugin page served from an allowed host", async () => {
|
||||
const socket = new WebSocket(`ws://127.0.0.1:${port}?userToken=alice`, {
|
||||
headers: { Origin: "http://localhost:4400" },
|
||||
});
|
||||
sockets.push(socket);
|
||||
await once(socket, "open");
|
||||
const initialized = once(socket, "message", { signal: AbortSignal.timeout(1500) });
|
||||
socket.send(JSON.stringify({ type: "initialize", session: { sessionId: "tab", fileId: null, fileName: null } }));
|
||||
const [message] = await initialized;
|
||||
assert.equal(JSON.parse(message.toString()).type, "initialized");
|
||||
});
|
||||
|
||||
@ -127,6 +127,14 @@ export class PluginBridge implements TaskDispatchHost {
|
||||
*/
|
||||
private setupWebSocketHandlers(): void {
|
||||
this.wsServer.on("connection", (ws: WebSocket, request: http.IncomingMessage) => {
|
||||
// reject pages on foreign sites before reading any message
|
||||
const guardResult = this.mcpServer.requestGuard.check(request.headers);
|
||||
if (!guardResult.isAllowed) {
|
||||
this.logger.warn("Rejected WebSocket connection: %s", guardResult.reason);
|
||||
ws.close(1008, "Origin or host not allowed; see PENPOT_MCP_ALLOWED_HOSTS");
|
||||
return;
|
||||
}
|
||||
|
||||
// extract userToken from query parameters
|
||||
const url = new URL(request.url!, `ws://${request.headers.host}`);
|
||||
const userToken = url.searchParams.get("userToken");
|
||||
|
||||
@ -5,6 +5,7 @@ import Redis, { type Command } from "ioredis";
|
||||
import { WebSocket } from "ws";
|
||||
import { RedisBridge } from "./RedisBridge";
|
||||
import { PluginBridge } from "./PluginBridge";
|
||||
import { RequestGuard } from "./RequestGuard";
|
||||
import { PluginTask } from "./PluginTask";
|
||||
import type { PenpotMcpServer } from "./PenpotMcpServer";
|
||||
import type { PenpotSession } from "@penpot/mcp-common";
|
||||
@ -163,6 +164,7 @@ function instance(t: TestContext) {
|
||||
host: "127.0.0.1",
|
||||
isMultiUserMode: () => true,
|
||||
getSessionContext: () => ({ userToken: "alice" }),
|
||||
requestGuard: RequestGuard.allowingAny(),
|
||||
} as PenpotMcpServer,
|
||||
wsPort,
|
||||
0.1,
|
||||
|
||||
@ -4,6 +4,7 @@ import { fileURLToPath } from "url";
|
||||
import { PluginBridge } from "./PluginBridge";
|
||||
import { ExecuteCodePluginTask } from "./tasks/ExecuteCodePluginTask";
|
||||
import { createLogger } from "./logger";
|
||||
import type { RequestGuard } from "./RequestGuard";
|
||||
|
||||
/**
|
||||
* Web-based REPL server for executing code through the PluginBridge.
|
||||
@ -22,6 +23,7 @@ export class ReplServer {
|
||||
|
||||
constructor(
|
||||
private readonly pluginBridge: PluginBridge,
|
||||
private readonly requestGuard: RequestGuard,
|
||||
port: number = 4403,
|
||||
host: string = "localhost"
|
||||
) {
|
||||
@ -36,6 +38,7 @@ export class ReplServer {
|
||||
* Sets up Express middleware for request parsing and static content.
|
||||
*/
|
||||
private setupMiddleware(): void {
|
||||
this.app.use(this.requestGuard.httpMiddleware);
|
||||
this.app.use(express.json());
|
||||
}
|
||||
|
||||
|
||||
60
mcp/packages/server/src/RequestGuard.test.ts
Normal file
60
mcp/packages/server/src/RequestGuard.test.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { RequestGuard } from "./RequestGuard";
|
||||
|
||||
test("single-user mode allows only loopback hosts and origins by default", () => {
|
||||
const guard = RequestGuard.fromEnvironment({}, false);
|
||||
assert.equal(guard.allowsAny(), false);
|
||||
assert.equal(guard.check({ host: "localhost:4401" }).isAllowed, true);
|
||||
assert.equal(guard.check({ host: "127.0.0.1:4401", origin: "http://localhost:4400" }).isAllowed, true);
|
||||
assert.equal(guard.check({ host: "[::1]:4401" }).isAllowed, true);
|
||||
assert.equal(guard.check({ host: "attacker.example:4401" }).isAllowed, false);
|
||||
assert.equal(guard.check({ host: "localhost:4401", origin: "https://attacker.example" }).isAllowed, false);
|
||||
assert.equal(guard.check({ host: "localhost:4401", origin: "null" }).isAllowed, false);
|
||||
assert.equal(guard.check({}).isAllowed, false);
|
||||
});
|
||||
|
||||
test("multi-user mode allows any host and origin by default", () => {
|
||||
const guard = RequestGuard.fromEnvironment({ PENPOT_MCP_ALLOWED_HOSTS: " , " }, true);
|
||||
assert.equal(guard.allowsAny(), true);
|
||||
assert.equal(guard.check({ host: "penpot.example.com", origin: "https://other.example" }).isAllowed, true);
|
||||
assert.equal(guard.describe(), "<any>");
|
||||
});
|
||||
|
||||
test("the configured hosts replace the default in either mode", () => {
|
||||
for (const isMultiUserMode of [false, true]) {
|
||||
const guard = RequestGuard.fromEnvironment(
|
||||
{ PENPOT_MCP_ALLOWED_HOSTS: " Penpot.Example.com, localhost " },
|
||||
isMultiUserMode
|
||||
);
|
||||
assert.equal(guard.describe(), "penpot.example.com, localhost");
|
||||
assert.equal(guard.check({ host: "penpot.example.com", origin: "https://penpot.example.com" }).isAllowed, true);
|
||||
assert.equal(guard.check({ host: "localhost:4401" }).isAllowed, true);
|
||||
assert.equal(guard.check({ host: "127.0.0.1:4401" }).isAllowed, false);
|
||||
assert.equal(guard.check({ host: "penpot.example.com", origin: "https://attacker.example" }).isAllowed, false);
|
||||
}
|
||||
});
|
||||
|
||||
test("the wildcard turns the check off in single-user mode", () => {
|
||||
const guard = RequestGuard.fromEnvironment({ PENPOT_MCP_ALLOWED_HOSTS: "localhost, *" }, false);
|
||||
assert.equal(guard.describe(), "<any>");
|
||||
assert.equal(guard.check({ host: "attacker.example", origin: "https://attacker.example" }).isAllowed, true);
|
||||
});
|
||||
|
||||
test("hostnames, bracketed IPv6 addresses and the wildcard are valid entries", () => {
|
||||
const guard = RequestGuard.fromEnvironment(
|
||||
{ PENPOT_MCP_ALLOWED_HOSTS: "localhost, 127.0.0.1, [::1], penpot-mcp, penpot_mcp, penpot.example.com" },
|
||||
false
|
||||
);
|
||||
assert.equal(guard.check({ host: "penpot-mcp:4402" }).isAllowed, true);
|
||||
assert.equal(guard.check({ host: "[::1]:4401" }).isAllowed, true);
|
||||
});
|
||||
|
||||
test("entries with a scheme, port or path stop the server from starting", () => {
|
||||
for (const entry of ["http://localhost", "localhost:4401", "localhost/", "[::1]:4401", "local host"]) {
|
||||
assert.throws(
|
||||
() => RequestGuard.fromEnvironment({ PENPOT_MCP_ALLOWED_HOSTS: `localhost, ${entry}` }, false),
|
||||
(error: Error) => error.message.includes(`"${entry}"`)
|
||||
);
|
||||
}
|
||||
});
|
||||
142
mcp/packages/server/src/RequestGuard.ts
Normal file
142
mcp/packages/server/src/RequestGuard.ts
Normal file
@ -0,0 +1,142 @@
|
||||
import type { IncomingHttpHeaders } from "node:http";
|
||||
import type { NextFunction, Request, Response } from "express";
|
||||
import { localhostAllowedHostnames, validateHostHeader, validateOriginHeader } from "@modelcontextprotocol/server";
|
||||
import { createLogger } from "./logger";
|
||||
|
||||
/**
|
||||
* Outcome of checking the headers of one request against a {@link RequestGuard}.
|
||||
*/
|
||||
export class RequestGuardResult {
|
||||
/**
|
||||
* @param isAllowed whether the request may proceed
|
||||
* @param reason why the request was rejected; empty when it is allowed
|
||||
*/
|
||||
constructor(
|
||||
public readonly isAllowed: boolean,
|
||||
public readonly reason: string = ""
|
||||
) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowlist check of the `Host` and `Origin` headers of requests reaching the MCP server.
|
||||
*
|
||||
* Any web page the user opens can send requests to servers on the user's machine. The `Host`
|
||||
* check stops DNS rebinding, where a page on a foreign domain whose name resolves to the
|
||||
* loopback address reaches the server as a same-origin request. The `Origin` check stops
|
||||
* pages on foreign sites from sending requests or opening the plugin WebSocket directly.
|
||||
* Both headers are compared by hostname only, ignoring the port. A request without an
|
||||
* `Origin` header comes from a client other than a browser and passes the `Origin` check.
|
||||
*
|
||||
* The allowed hostnames come from `PENPOT_MCP_ALLOWED_HOSTS`, where `*` allows any hostname.
|
||||
* When it is unset, single-user mode allows only loopback hostnames, in local and remote mode
|
||||
* alike, since it has no other barrier. Multi-user mode allows any hostname, since its server
|
||||
* is reached under names it cannot know and relies on user tokens instead.
|
||||
*/
|
||||
export class RequestGuard {
|
||||
/**
|
||||
* Pattern of a valid allowlist entry: a hostname or a bracketed IPv6 address, without scheme or port.
|
||||
*/
|
||||
private static readonly HOSTNAME_PATTERN = /^(?:[a-z0-9_-]+(?:\.[a-z0-9_-]+)*|\[[0-9a-f:.]+\])$/;
|
||||
|
||||
private readonly logger = createLogger("RequestGuard");
|
||||
|
||||
/**
|
||||
* @param allowedHostnames the hostnames allowed in `Host` and `Origin`, or null to allow any
|
||||
*/
|
||||
private constructor(private readonly allowedHostnames: string[] | null) {}
|
||||
|
||||
/**
|
||||
* Creates the guard configured by `PENPOT_MCP_ALLOWED_HOSTS`.
|
||||
*
|
||||
* The variable holds a comma-separated list of hostnames, without ports; IPv6 addresses
|
||||
* go in brackets (e.g. `[::1]`). The entry `*` allows any hostname, which turns the check off.
|
||||
*
|
||||
* @param env the environment variables
|
||||
* @param isMultiUserMode whether the server runs in multi-user mode
|
||||
* @throws Error if an entry is neither `*` nor a hostname, e.g. when it has a scheme or port
|
||||
*/
|
||||
public static fromEnvironment(env: Record<string, string | undefined>, isMultiUserMode: boolean): RequestGuard {
|
||||
const configured = (env.PENPOT_MCP_ALLOWED_HOSTS ?? "")
|
||||
.split(",")
|
||||
.map((hostname) => hostname.trim().toLowerCase())
|
||||
.filter((hostname) => hostname.length > 0);
|
||||
for (const hostname of configured) {
|
||||
if (hostname !== "*" && !RequestGuard.HOSTNAME_PATTERN.test(hostname)) {
|
||||
throw new Error(
|
||||
`PENPOT_MCP_ALLOWED_HOSTS entry "${hostname}" is not a hostname; ` +
|
||||
"give hostnames without scheme, port or path (e.g. localhost, [::1])"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (configured.includes("*")) {
|
||||
return RequestGuard.allowingAny();
|
||||
}
|
||||
if (configured.length > 0) {
|
||||
return new RequestGuard(configured);
|
||||
}
|
||||
return isMultiUserMode ? RequestGuard.allowingAny() : RequestGuard.allowing(localhostAllowedHostnames());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a guard that allows only the given hostnames.
|
||||
*/
|
||||
public static allowing(hostnames: string[]): RequestGuard {
|
||||
return new RequestGuard([...hostnames]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a guard that allows every request.
|
||||
*/
|
||||
public static allowingAny(): RequestGuard {
|
||||
return new RequestGuard(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the guard allows every request.
|
||||
*/
|
||||
public allowsAny(): boolean {
|
||||
return this.allowedHostnames === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the allowed hostnames, for logging.
|
||||
*/
|
||||
public describe(): string {
|
||||
return this.allowedHostnames === null ? "<any>" : this.allowedHostnames.join(", ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the `Host` and `Origin` headers of a request.
|
||||
*/
|
||||
public check(headers: IncomingHttpHeaders): RequestGuardResult {
|
||||
if (this.allowedHostnames === null) {
|
||||
return new RequestGuardResult(true);
|
||||
}
|
||||
const host = validateHostHeader(headers.host, this.allowedHostnames);
|
||||
if (!host.ok) {
|
||||
return new RequestGuardResult(false, host.message);
|
||||
}
|
||||
const origin = validateOriginHeader(headers.origin, this.allowedHostnames);
|
||||
if (!origin.ok) {
|
||||
return new RequestGuardResult(false, origin.message);
|
||||
}
|
||||
return new RequestGuardResult(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Express middleware that answers a rejected request with HTTP 403.
|
||||
*/
|
||||
public readonly httpMiddleware = (req: Request, res: Response, next: NextFunction): void => {
|
||||
const result = this.check(req.headers);
|
||||
if (result.isAllowed) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
this.logger.warn("Rejected HTTP request to %s: %s", req.path, result.reason);
|
||||
res.status(403).json({
|
||||
jsonrpc: "2.0",
|
||||
error: { code: -32000, message: `${result.reason}; see PENPOT_MCP_ALLOWED_HOSTS` },
|
||||
id: null,
|
||||
});
|
||||
};
|
||||
}
|
||||
@ -2,12 +2,14 @@
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- **plugin-types, plugins-runtime:** Added `penpot.waitForSave(timeout?)` to wait until pending file changes are saved (or there is nothing to save). Rejects on save failure, rollback during the wait, timeout (default 60000 ms), or an invalid timeout. The Error `code` property is `save-timeout`, `rolled-back`, `save-retrying` (an earlier failed save Penpot keeps retrying) or the save failure code.
|
||||
- **plugin-types, plugins-runtime:** `penpotMgmt` returns `Team`, `Project` and `ProjectFile` objects. Assigning `name` renames teams, projects and files, `project.pinned` pins a project and `file.shared` shares a file as a team library; `createProject`, `createFile`, `moveTo`, `duplicate`, `remove` and `restore` live on the objects. Added `penpotMgmt.listTeams`, `penpotMgmt.createTeam`, `penpotMgmt.getFile`, `listDeletedProjects` and `listDeletedFiles`, and the `manage:projects`, `manage:teams` and `manage:delete` permissions. Restoration uses the dashboard's Trash operation; projects need recoverable files and empty projects cannot be restored; the API exposes no permanent deletion method. Team deletion is not exposed.
|
||||
- **plugins-runtime, plugin-types**: Added global plugins (`scope: "global"`) that remain active across dashboard and workspace navigation until closed or logged out, with `penpotMgmt` for project and file discovery, file navigation and workspace events. Global scope adds the `allow:global` permission, which users must accept when installing the plugin.
|
||||
- **plugin-types:** Added the `contentrollback` event and the `ContentRollback` type. The event fires after the backend rejected some changes and the workspace undid them, with the ids of the files, pages and shapes affected. It fires once the undone data is in the workspace, also when the workspace has to reload the file to undo the changes.
|
||||
|
||||
### 🩹 Fixes
|
||||
|
||||
- **plugins-runtime:** Methods that rejected an invalid value with a plain string (`connectLibrary`, file `restore`, `remove`, `pin`, `export`, `findVersions`, `saveVersion`) now reject with an `Error` carrying the same message.
|
||||
- **plugin-runtime:** `LibraryComponent.instance()`, `createShapeFromSvg()` and `createShapeFromSvgWithImages()` now create shapes at the page root instead of inside a board at the page origin. Closes #12086.
|
||||
- **plugin-types, plugin-runtime:** Dashboard property setters now update values after backend success and log failures without interrupting the workspace. File moves reject projects in other teams, backend rejections include their type and code, and `project.fileCount` stays at its listing snapshot. Duplicated projects include their file count and pinned state.
|
||||
- **plugin-runtime:** Cancel plugin loads before they execute after unloading or logout, and allow reopening plugins that close during startup.
|
||||
|
||||
@ -74,6 +74,7 @@
|
||||
"verticalPadding",
|
||||
"verticalSizing"
|
||||
],
|
||||
"ContentRollback": ["fileIds", "pageIds", "shapeIds"],
|
||||
"Context": [
|
||||
"activeUsers",
|
||||
"alignHorizontal",
|
||||
@ -115,7 +116,8 @@
|
||||
"uploadMediaUrl",
|
||||
"version",
|
||||
"viewport",
|
||||
"waitForLayoutUpdate"
|
||||
"waitForLayoutUpdate",
|
||||
"waitForSave"
|
||||
],
|
||||
"ContextGeometryUtils": ["center"],
|
||||
"ContextTypesUtils": [
|
||||
@ -135,6 +137,7 @@
|
||||
"Dissolve": ["duration", "easing", "type"],
|
||||
"Ellipse": ["fills", "type"],
|
||||
"EventsMap": [
|
||||
"contentrollback",
|
||||
"contentsave",
|
||||
"filechange",
|
||||
"finish",
|
||||
@ -376,6 +379,8 @@
|
||||
"PenpotMgmt": [
|
||||
"createTeam",
|
||||
"getFile",
|
||||
"listDeletedFiles",
|
||||
"listDeletedProjects",
|
||||
"listProjects",
|
||||
"listTeams",
|
||||
"off",
|
||||
@ -399,11 +404,13 @@
|
||||
"fileCount",
|
||||
"id",
|
||||
"isDefault",
|
||||
"listDeletedFiles",
|
||||
"listFiles",
|
||||
"moveTo",
|
||||
"name",
|
||||
"pinned",
|
||||
"remove",
|
||||
"restore",
|
||||
"teamId"
|
||||
],
|
||||
"ProjectFile": [
|
||||
@ -415,6 +422,7 @@
|
||||
"open",
|
||||
"projectId",
|
||||
"remove",
|
||||
"restore",
|
||||
"shared",
|
||||
"teamId"
|
||||
],
|
||||
@ -528,9 +536,10 @@
|
||||
"createProject",
|
||||
"id",
|
||||
"isDefault",
|
||||
"listDeletedFiles",
|
||||
"listDeletedProjects",
|
||||
"listProjects",
|
||||
"name",
|
||||
"remove"
|
||||
"name"
|
||||
],
|
||||
"Text": [
|
||||
"align",
|
||||
@ -2145,6 +2154,26 @@
|
||||
"array": false
|
||||
}
|
||||
},
|
||||
"ContentRollback": {
|
||||
"fileIds": {
|
||||
"decl": "ContentRollback",
|
||||
"kind": "get",
|
||||
"type": null,
|
||||
"array": true
|
||||
},
|
||||
"pageIds": {
|
||||
"decl": "ContentRollback",
|
||||
"kind": "get",
|
||||
"type": null,
|
||||
"array": true
|
||||
},
|
||||
"shapeIds": {
|
||||
"decl": "ContentRollback",
|
||||
"kind": "get",
|
||||
"type": null,
|
||||
"array": true
|
||||
}
|
||||
},
|
||||
"Context": {
|
||||
"management": {
|
||||
"decl": "Context",
|
||||
@ -2409,6 +2438,12 @@
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
},
|
||||
"waitForSave": {
|
||||
"decl": "Context",
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
}
|
||||
},
|
||||
"ContextGeometryUtils": {
|
||||
@ -3045,6 +3080,12 @@
|
||||
"kind": "get",
|
||||
"type": null,
|
||||
"array": false
|
||||
},
|
||||
"contentrollback": {
|
||||
"decl": "EventsMap",
|
||||
"kind": "get",
|
||||
"type": "ContentRollback",
|
||||
"array": false
|
||||
}
|
||||
},
|
||||
"Export": {
|
||||
@ -6843,6 +6884,12 @@
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
},
|
||||
"waitForSave": {
|
||||
"decl": "Context",
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
}
|
||||
},
|
||||
"PenpotMgmt": {
|
||||
@ -6870,6 +6917,18 @@
|
||||
"type": "Project",
|
||||
"array": true
|
||||
},
|
||||
"listDeletedProjects": {
|
||||
"decl": "PenpotMgmt",
|
||||
"kind": "method",
|
||||
"type": "Project",
|
||||
"array": true
|
||||
},
|
||||
"listDeletedFiles": {
|
||||
"decl": "PenpotMgmt",
|
||||
"kind": "method",
|
||||
"type": "ProjectFile",
|
||||
"array": true
|
||||
},
|
||||
"getFile": {
|
||||
"decl": "PenpotMgmt",
|
||||
"kind": "method",
|
||||
@ -6998,6 +7057,18 @@
|
||||
"type": "ProjectFile",
|
||||
"array": true
|
||||
},
|
||||
"listDeletedFiles": {
|
||||
"decl": "Project",
|
||||
"kind": "method",
|
||||
"type": "ProjectFile",
|
||||
"array": true
|
||||
},
|
||||
"restore": {
|
||||
"decl": "Project",
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
},
|
||||
"createFile": {
|
||||
"decl": "Project",
|
||||
"kind": "method",
|
||||
@ -7066,6 +7137,12 @@
|
||||
"type": null,
|
||||
"array": false
|
||||
},
|
||||
"restore": {
|
||||
"decl": "ProjectFile",
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
},
|
||||
"moveTo": {
|
||||
"decl": "ProjectFile",
|
||||
"kind": "method",
|
||||
@ -8752,17 +8829,23 @@
|
||||
"type": "Project",
|
||||
"array": true
|
||||
},
|
||||
"listDeletedProjects": {
|
||||
"decl": "Team",
|
||||
"kind": "method",
|
||||
"type": "Project",
|
||||
"array": true
|
||||
},
|
||||
"listDeletedFiles": {
|
||||
"decl": "Team",
|
||||
"kind": "method",
|
||||
"type": "ProjectFile",
|
||||
"array": true
|
||||
},
|
||||
"createProject": {
|
||||
"decl": "Team",
|
||||
"kind": "method",
|
||||
"type": "Project",
|
||||
"array": false
|
||||
},
|
||||
"remove": {
|
||||
"decl": "Team",
|
||||
"kind": "method",
|
||||
"type": null,
|
||||
"array": false
|
||||
}
|
||||
},
|
||||
"Text": {
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
import { expect, expectReject } from '../framework/expect';
|
||||
import { describe, test } from '../framework/registry';
|
||||
|
||||
// waitForSave: resolves once the pending file changes are saved, or when
|
||||
// there is nothing to save. It waits on the shared persistence queue, so the
|
||||
// edits of earlier tests may be in flight too; each test only asserts what
|
||||
// holds whatever else is queued.
|
||||
|
||||
describe('WaitForSave', () => {
|
||||
test('resolves after an edit is saved', async (ctx) => {
|
||||
const r = ctx.penpot.createRectangle();
|
||||
ctx.board.appendChild(r);
|
||||
r.name = 'wait-save-probe';
|
||||
|
||||
const value = await ctx.penpot.waitForSave();
|
||||
expect(value).toBeUndefined();
|
||||
expect(r.name).toBe('wait-save-probe');
|
||||
});
|
||||
|
||||
test('resolves when there is nothing to save', async (ctx) => {
|
||||
await ctx.penpot.waitForSave();
|
||||
await ctx.penpot.waitForSave(5000);
|
||||
});
|
||||
|
||||
test('rejects an invalid timeout with an Error', async (ctx) => {
|
||||
for (const value of [
|
||||
-1,
|
||||
0,
|
||||
Number.NaN,
|
||||
Number.POSITIVE_INFINITY,
|
||||
2 ** 31,
|
||||
]) {
|
||||
const p = ctx.penpot.waitForSave(value);
|
||||
expect(p instanceof Promise).toBe(true);
|
||||
await expectReject(p, /not valid/);
|
||||
const error = await p.catch((e: unknown) => e);
|
||||
expect(error instanceof Error).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
18
plugins/libs/plugin-types/index.d.ts
vendored
18
plugins/libs/plugin-types/index.d.ts
vendored
@ -1630,6 +1630,24 @@ export interface Context {
|
||||
* rejected with an Error, both on timeout and on an invalid timeout value.
|
||||
*/
|
||||
waitForLayoutUpdate(timeout?: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* This method returns a promise that will be resolved when pending file
|
||||
* changes have been saved to the backend, or when there is nothing to save.
|
||||
* It force-flushes the persistence buffer first when work is pending.
|
||||
* @param timeout Maximum time to wait, in milliseconds. If the timeout
|
||||
* elapses before the save settles, the promise is rejected. Defaults to
|
||||
* 60000; the promise never waits indefinitely.
|
||||
* @return The promise to be resolved when the save has settled. It is
|
||||
* rejected with an Error on save failure, when changes are rolled back
|
||||
* during the wait, on timeout, or on an invalid timeout value. A save
|
||||
* that failed before the call also rejects: with `save-retrying` while
|
||||
* Penpot keeps retrying it, otherwise with the failure code until the
|
||||
* file is reopened. The Error `code` property tells the cases apart:
|
||||
* `save-timeout`, `rolled-back`, `save-retrying`, or the failure code
|
||||
* (`save-failed` unless the backend gave a more specific one).
|
||||
*/
|
||||
waitForSave(timeout?: number): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -413,6 +413,11 @@ export function createApi(
|
||||
checkPermission('content:read');
|
||||
return plugin.context.waitForLayoutUpdate(timeout);
|
||||
},
|
||||
|
||||
waitForSave(timeout?: number): Promise<void> {
|
||||
checkPermission('content:read');
|
||||
return plugin.context.waitForSave(timeout);
|
||||
},
|
||||
};
|
||||
|
||||
const penpotMgmt: PenpotMgmt = {
|
||||
|
||||
@ -37,6 +37,8 @@ describe('Plugin api', () => {
|
||||
theme: 'dark',
|
||||
addListener: vi.fn().mockReturnValueOnce(Symbol()),
|
||||
removeListener: vi.fn(),
|
||||
waitForSave: vi.fn().mockResolvedValue(undefined),
|
||||
waitForLayoutUpdate: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -186,6 +188,30 @@ describe('Plugin api', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('waitForSave', () => {
|
||||
it('forwards to plugin.context.waitForSave', async () => {
|
||||
await expect(api.penpot.waitForSave(1234)).resolves.toBeUndefined();
|
||||
expect(pluginManager.context.waitForSave).toHaveBeenCalledWith(1234);
|
||||
});
|
||||
|
||||
it('requires content:read', () => {
|
||||
const waitForSave = vi.fn().mockResolvedValue(undefined);
|
||||
const { penpot } = createApi({
|
||||
...pluginManager,
|
||||
manifest: {
|
||||
...pluginManager.manifest,
|
||||
permissions: [],
|
||||
},
|
||||
context: { ...pluginManager.context, waitForSave },
|
||||
} as any);
|
||||
|
||||
expect(() => penpot.waitForSave(100)).toThrow(
|
||||
'Permission content:read is not granted',
|
||||
);
|
||||
expect(waitForSave).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ui', () => {
|
||||
describe.concurrent('permissions', () => {
|
||||
const api = createApi({
|
||||
|
||||
@ -4,7 +4,7 @@ Check commit messages against Penpot's commit guidelines.
|
||||
|
||||
Validates commit messages using the rules defined in:
|
||||
- .github/workflows/commit-checker.yml (regex pattern)
|
||||
- CONTRIBUTING.md (formatting rules, subject length, DCO)
|
||||
- CONTRIBUTING.md (formatting rules, subject length)
|
||||
- .serena/memories/workflow/creating-commits.md (body wrapped at 80 chars)
|
||||
|
||||
By default, checks HEAD. Use --commit to specify a different commit.
|
||||
@ -53,11 +53,26 @@ MAX_SUBJECT_LINE = 80
|
||||
MAX_BODY_LINE = 80
|
||||
|
||||
TRAILER_PATTERN = re.compile(
|
||||
r"^(Signed-off-by|Co-developed-by|Reviewed-by|"
|
||||
r"^(Signed-off-by|Co-authored-by|Co-developed-by|Reviewed-by|"
|
||||
r"Acked-by|Tested-by|Reported-by|Suggested-by|AI-assisted-by):"
|
||||
)
|
||||
|
||||
FORBIDDEN_TRAILER_PATTERN = re.compile(r"^\s*Co-authored-by\s*:", re.IGNORECASE)
|
||||
# ── Co-authored-by trailer ───────────────────────────────────────────────────
|
||||
# A human co-author may be credited with Co-authored-by. The trailer is
|
||||
# forbidden when its value names an AI provider, an AI agent, or a bot: for AI
|
||||
# participation the message uses "AI-assisted-by: <model>" instead.
|
||||
# Extend this list when a new tool starts adding trailers.
|
||||
NON_HUMAN_COAUTHOR_PATTERN = re.compile(
|
||||
r"^\s*co-authored-by\s*:.*("
|
||||
r"\b(?:chatgpt|openai|anthropic|claude|copilot|codex|gemini|bard|"
|
||||
r"deepseek|mistral|qwen|kimi|llama|grok|cursor|"
|
||||
r"windsurf|cline|aider|codeium|tabnine|amazon\s+q|sourcegraph\s+cody|"
|
||||
r"roo\s+code|kilo\s+code|opencode)\b"
|
||||
r"|\bdevin-ai|@devin\.ai"
|
||||
r"|\[bot\]|\bbot@"
|
||||
r")",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
URL_PATTERN = re.compile(r"https?://\S+")
|
||||
|
||||
@ -249,23 +264,12 @@ def check_body_line_length(message):
|
||||
)
|
||||
|
||||
|
||||
def check_signed_off_by(message):
|
||||
"""Check for the DCO Signed-off-by line (required for code changes)."""
|
||||
if "Signed-off-by:" not in message:
|
||||
return False, (
|
||||
"Missing 'Signed-off-by:' line in the commit footer.\n"
|
||||
" Add it with 'git commit -s' or append it manually:\n"
|
||||
" Signed-off-by: Your Real Name <your.email@example.com>"
|
||||
)
|
||||
return True, None
|
||||
|
||||
|
||||
def check_no_co_authored_by(message):
|
||||
"""Check that the forbidden Co-authored-by trailer is absent."""
|
||||
def check_co_authored_by(message):
|
||||
"""Co-authored-by is allowed for humans, not for AI providers or bots."""
|
||||
offenders = [
|
||||
(line_number, line)
|
||||
for line_number, line in enumerate(message.split("\n"), start=1)
|
||||
if FORBIDDEN_TRAILER_PATTERN.match(line)
|
||||
if NON_HUMAN_COAUTHOR_PATTERN.match(line)
|
||||
]
|
||||
if not offenders:
|
||||
return True, None
|
||||
@ -274,8 +278,10 @@ def check_no_co_authored_by(message):
|
||||
for line_number, line in offenders
|
||||
)
|
||||
return False, (
|
||||
"The 'Co-authored-by:' trailer is forbidden and must not appear "
|
||||
"in the commit message. Offending line(s):\n" + details
|
||||
"The 'Co-authored-by:' trailer is only for human co-authors. This one "
|
||||
"names an AI provider, an AI agent, or a bot. Offending line(s):\n"
|
||||
+ details
|
||||
+ "\n For AI participation use: AI-assisted-by: <model-name>"
|
||||
)
|
||||
|
||||
|
||||
@ -313,7 +319,7 @@ def main():
|
||||
("Subject capitalized", check_subject_capitalized),
|
||||
("Blank line after subject", check_body_blank_line),
|
||||
("Body wrapped at 80 chars", check_body_line_length),
|
||||
("No Co-authored-by trailer", check_no_co_authored_by),
|
||||
("Co-authored-by is human only", check_co_authored_by),
|
||||
]
|
||||
|
||||
all_ok = True
|
||||
|
||||
@ -6,7 +6,9 @@ Run with:
|
||||
python3 scripts/test_check_commit.py
|
||||
|
||||
Covers the commit message rules enforced by scripts/check-commit and documented
|
||||
in .serena/memories/workflow/creating-commits.md.
|
||||
in .serena/memories/workflow/creating-commits.md: the body line-wrapping
|
||||
validator, the Co-authored-by validator (which allows human co-authors and
|
||||
rejects AI providers and bots), and message checking from files.
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
@ -92,6 +94,14 @@ class BodyLineLengthTests(unittest.TestCase):
|
||||
line = "Signed-off-by: Someone With A Long Name <someone@example.com>"
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\n" + line + "\n")
|
||||
|
||||
def test_human_co_author_trailer_passes(self):
|
||||
line = (
|
||||
"Co-authored-by: Someone With A Very Long Name "
|
||||
"<someone.with.a.long.address@example.com>"
|
||||
)
|
||||
self.assertGreater(len(line), 80)
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\n" + line + "\n")
|
||||
|
||||
def test_unbreakable_token_passes(self):
|
||||
line = "a" * 100 # no whitespace to wrap at
|
||||
self.assert_ok(":bug: Fix crash\n\n" + line + "\n")
|
||||
@ -111,14 +121,16 @@ class BodyLineLengthTests(unittest.TestCase):
|
||||
self.assertIn("line 4", error)
|
||||
|
||||
|
||||
class ForbiddenTrailerTests(unittest.TestCase):
|
||||
class CoAuthorTrailerTests(unittest.TestCase):
|
||||
"""Co-authored-by is allowed for humans, forbidden for AI providers/bots."""
|
||||
|
||||
def assert_ok(self, message):
|
||||
ok, error = check_commit.check_no_co_authored_by(message)
|
||||
ok, error = check_commit.check_co_authored_by(message)
|
||||
self.assertTrue(ok, error)
|
||||
self.assertIsNone(error)
|
||||
|
||||
def assert_fail(self, message):
|
||||
ok, error = check_commit.check_no_co_authored_by(message)
|
||||
ok, error = check_commit.check_co_authored_by(message)
|
||||
self.assertFalse(ok)
|
||||
self.assertIsNotNone(error)
|
||||
return error
|
||||
@ -126,15 +138,57 @@ class ForbiddenTrailerTests(unittest.TestCase):
|
||||
def test_body_without_trailer_passes(self):
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\nSigned-off-by: Someone <someone@example.com>\n")
|
||||
|
||||
def test_co_authored_by_fails(self):
|
||||
error = self.assert_fail(":bug: Fix crash\n\nBody.\n\nCo-authored-by: Someone <someone@example.com>\n")
|
||||
self.assertIn("Co-authored-by", error)
|
||||
def test_human_co_author_passes(self):
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\nCo-authored-by: Jane Doe <jane@example.com>\n")
|
||||
|
||||
def test_co_authored_by_case_insensitive_fails(self):
|
||||
self.assert_fail(":bug: Fix crash\n\nBody.\n\nco-authored-by: Someone <someone@example.com>\n")
|
||||
def test_human_with_github_noreply_email_passes(self):
|
||||
self.assert_ok(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Jane Doe <1234+jane@users.noreply.github.com>\n"
|
||||
)
|
||||
|
||||
def test_human_whose_email_ends_with_bot_passes(self):
|
||||
# "abbot@" must not count as a "bot@" identity.
|
||||
self.assert_ok(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Jane Abbot <abbot@example.com>\n"
|
||||
)
|
||||
|
||||
def test_claude_fails(self):
|
||||
error = self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Claude <noreply@anthropic.com>\n"
|
||||
)
|
||||
self.assertIn("Co-authored-by", error)
|
||||
self.assertIn("AI-assisted-by", error)
|
||||
|
||||
def test_cursor_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Cursor Agent <cursoragent@cursor.com>\n"
|
||||
)
|
||||
|
||||
def test_copilot_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>\n"
|
||||
)
|
||||
|
||||
def test_case_insensitive_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\nco-authored-by: CHATGPT <x@example.com>\n"
|
||||
)
|
||||
|
||||
def test_bot_identity_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: dependabot[bot] <support@github.com>\n"
|
||||
)
|
||||
|
||||
def test_co_authored_by_in_body_fails(self):
|
||||
self.assert_fail(":bug: Fix crash\n\nCo-authored-by: Someone <someone@example.com>\nBody.\n")
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nCo-authored-by: Gemini <gemini@example.com>\nBody.\n"
|
||||
)
|
||||
|
||||
def test_similar_trailer_passes(self):
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\nCo-developed-by: Someone <someone@example.com>\n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user