Behaviour SwRS-MDOKFSTUDIO-TRUST-001
A document is editable whatever the trust; only its reads are restricted
When a preview is created for a document that lies in no workspace folder, or while the workspace is untrusted, the extension SHALL keep every editing affordance on, as in a trusted workspace, and narrow only what the preview reads.
Step 1 of path 1 in StRS-MDOKFSTUDIO-TRUST-001: from “A preview is created for a document in no workspace folder, or in an untrusted workspace” to “The document is editable”.
Part of StRS-MDOKFSTUDIO-BLOCK-001, outside the paths drawn on its map.
Scenarios 5
The situations the tests check; open one to read it.
nominalRestricted reads at creation
Givena Markdown document and a window
Whenthe reader opens the preview with the Open Preview to Side command or with Open With
Thenthe preview has full reads when the document lies inside a folder of a trusted workspace, and restricted reads otherwise; in both cases it is editable
| Input | Outcome |
|---|---|
| Trusted workspace, document inside one of its folders | Full reads, editable |
| Window in Restricted Mode (untrusted workspace) | Restricted reads, editable; the command preview and the Open With editor report restrictedReads true |
| Markdown file that lies in no workspace folder of a trusted window (standalone file) | Restricted reads, editable |
| A file that VS Code holds read-only (files.readonlyInclude, or made read-only in the session) | The preview offers the same controls; every write path (label rename, thread reply and delete, find and replace, block save, move, cut, paste, drop, checkbox and radio toggle, metadata save) checks that VS Code wrote the edit, and answers "This file is read-only in VS Code." when it accepted the edit and left the text unchanged; a pasted image whose block save fails that way is deleted again |
nominalEvery editing affordance is present
Givena preview with restricted reads of a document with at least five frontmatter fields, a table and a paragraph
Whenthe reader looks at the page and acts on it
Theneach affordance below is present and works as in a trusted workspace
| Affordance | In a preview with restricted reads |
|---|---|
| Edit button | Enabled: the toolbar holds the same four rows with 16 buttons, the Edit button has no aria-disabled attribute and its title and tooltip say "Edit mode"; a click toggles the edit mode |
| Edit mode at start | Off, or on when the saved state of the same document holds edit mode true |
| Edition palette | Built, and the palette mode message previewPaletteModeChanged is posted and stored for the workspace |
| Comment button | Installed (the runtime context carries commentsEnabled true); Cmd+Alt+M or Ctrl+Alt+M opens the comment box |
| Thread popover | The reply box and the Resolve and Delete buttons exist |
| Properties table | The name and value cells carry data-okf-edit-cell and the rows say data-okf-editable true |
| Edit target under the pointer | With edit mode on, a paragraph under the pointer is outlined as the block a click would edit (see SwRS-MDOKFSTUDIO-BLOCK-017) |
| Click on a paragraph, a table cell, a frontmatter value | The block, cell or field editor opens (see SwRS-MDOKFSTUDIO-TABLE-001 and SwRS-MDOKFSTUDIO-FMEDIT-001) |
| Checkboxes and radio options | Enabled; a click is written to the source |
boundaryWhat stays off because it needs trust
Givena preview with restricted reads
Whenthe reader uses a feature of the table
Thenthe feature is off, and the reason is shown where it is used or in the existing diagnostics; there is no banner
| Feature that needs trust | In a preview with restricted reads |
|---|---|
| PlantUML with Java (the jar pipeline) | No process starts; the diagram shows "PlantUML preview is disabled in an untrusted workspace." (see SwRS-MDOKFSTUDIO-DIAG-024) |
| Includes, images and resources | Read from the folder of the document only, never below a dot-directory, images only outside it (see SwRS-MDOKFSTUDIO-TRUST-002) |
| Schema lookup of the properties table | Not resolved; the generic table shows an info row (see SwRS-MDOKFSTUDIO-FMSCHEMA-019) |
| Citation list of the palette | Refused with "Listing citations searches the workspace for .bib files, which needs a trusted workspace folder that holds this file." (see SwRS-MDOKFSTUDIO-TRUST-005) |
| Linked scripts of the document | Not allowed (the sanitizer removes them in every mode) |
| MyST extension warnings in the Problems view, and the incoming-change marks | Published only for a trusted workspace (see SwRS-MDOKFSTUDIO-MYST-078); the incoming-change marks are posted for a trusted, tracked file only |
| Workspace values of the restricted settings | Ignored (see the manifest scenario) |
boundaryTrust granted or a folder added while a preview is open
| Input | Outcome |
|---|---|
| A preview created in an untrusted workspace, then the reader trusts the workspace | The preview moves to a session with full reads without being reopened: it renders once and keeps its reading state; its resource roots and navigation roots become the workspace folders |
| A preview created in a trusted workspace, then trust is granted again | It keeps its session |
| A preview of a file in no workspace folder of a trusted window, then a folder that holds the file is added (in the Agents window, the folder of the agent session becomes active) | The preview moves to a session of that folder with full reads on the same panel, renders once and keeps its reading state; the active preview stays the active one |
| The same, for a preview of a file that the added folder does not hold | It keeps restricted reads, on its own session |
| Any of the above while the preview has an open block, cell or field editor | The page is asked to save and close its editor first (the previewFlushEdit request, as before a document switch), then the session is replaced: the typed text is kept |
A preview whose folder is removed gets restricted reads on the same panel: see SwRS-MDOKFSTUDIO-LIFE-143.
boundaryThe manifest declares limited support for untrusted workspaces
Giventhe package.json of the extension, which has a main entry point
WhenVS Code decides whether the extension runs in a window in Restricted Mode
Thenthe extension runs, because the manifest declares the limited support, and its description says that editing stays on and reads are narrowed
| Input | Outcome |
|---|---|
| capabilities.untrustedWorkspaces.supported in package.json | "limited", with a description that says the reader can still edit, and does not call the preview read-only |
| capabilities.untrustedWorkspaces.restrictedConfigurations | The PlantUML engine settings plantuml.useJar and plantuml.jarPath, and the frontmatter path settings frontmatter.bundleRoot, frontmatter.projectRoot and frontmatter.allowOutsideWorkspaceLinks: a value from the workspace is ignored in Restricted Mode. The list is generated from the settings registry by just generate-settings |
| A manifest without the declaration, or with another value | The check fails (VS Code then disables a packaged extension in Restricted Mode) |
Implemented in 13
- src/core/configuration/settingsRegistry.ts
- src/core/edits/readOnlyReasons.ts
- src/core/frontmatter/propertiesTable.ts
- src/page/features/blockSourceEditor.ts
- src/page/features/editMode.ts
- src/page/features/pageInput.ts
- src/page/modules/commentThreads.ts
- src/page/runtime.ts
- src/session/features/viewState.ts
- src/session/hostEvents.ts
- src/session/previewManager.ts
- src/session/sessionDocuments.ts
- src/session/sessionFactory.ts
Tested by 16
- test/core/preview/previewStyles.test.tsunit
- test/host/fmtableReq.requirements.test.tsunit
- test/host/lifeReq.requirements.test.tsunit
- test/integration/commentWrite.test.tsintegration
- test/integration/standalone-suite.tsintegration
- test/integration/untrusted-suite.tsintegration
- test/page/modules/commentThreads.test.tsunit
- test/security/trustReq.requirements.test.tsunit
- test/session/blockReq.requirements.test.tsunit
- test/session/dropFiles.requirements.test.tsunit
- test/session/readOnlyFirstLoad.test.tsunit
- test/session/readOnlyImagesSession.test.tsunit
- test/session/renderReq.labelRename.requirements.test.tsunit
- test/session/reviewReqThreads.requirements.test.tsunit
- test/visual/capture_layout_checks.pyvisual
- test/visual/scenarioDefinitions2.tsvisual