Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-TRUST-005

The host handles the page messages of every preview, whatever the trust

When the host receives a page message from a preview, the extension SHALL handle it as for a trusted workspace, whether the preview belongs to a trusted workspace, to Restricted Mode or to a standalone file, and SHALL refuse a write request only for a reason that does not depend on trust (an older render, an open edit, a document that is not a saved file, a file VS Code holds read-only, a malformed request) or because it needs a read that Restricted Mode narrows (the citation list). A refusal names its real cause and changes nothing.

Step 2 of path 1 in StRS-MDOKFSTUDIO-TRUST-001: from “The document is editable” to “The edit is written to the document”.

Part of StRS-MDOKFSTUDIO-BLOCK-014, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-BLOCK-025, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-BLOCK-016, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-BLOCK-006, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-PALETTE-018, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-PALETTE-013, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-TOOLBAR-001, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-TOOLBAR-009, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-TOOLBAR-011, outside the paths drawn on its map.

Scenarios 6

The situations the tests check; open one to read it.

nominalEvery write request type is handled
Givena preview with restricted reads (an untrusted workspace, or a file outside every workspace folder) and a valid, current write request of any type in the table
Whenthe host receives the request
Thenthe request is handled by the handler of its type, as in a trusted workspace
Request typeOutcome in a preview with restricted reads
previewEditOpen, previewEditSave, previewEditCancelthe block editor opens, saves and closes; the document is edited
previewFrontmatterSavethe frontmatter is saved in one document edit
previewCheckboxTogglethe checkbox or radio option is written to the source
previewBlockMovethe two blocks swap in one edit
previewBlocksCopy, previewBlocksCut, previewBlocksPaste, previewDropFilesthe blocks are copied, cut and pasted; dropped files are written as links, a Markdown file without a title read in a preview with restricted reads, and for a standalone document any file, linked relative to the document
previewLabelRenamethe label line is renamed
previewThreadReply, previewThreadDeletethe thread comment is changed in the document
previewFindReplacethe matched spans are replaced in one undo step
previewCommentCreate, previewCommentReply, previewCommentResolve, previewCommentDeletethe comments file next to the document is read and written
previewPickDocumentthe document dialog opens
previewPickImagethe image dialog opens; the picked image must lie in a workspace folder, or in the folder of the document for a standalone file ("The image must be inside the folder of the document.")
previewPasteImagethe image is saved next to the document; for a standalone file the folder of the document is the root, for a document in a workspace folder that folder is
previewPaletteModeChanged, previewEditModeChangedthe choice is stored for the workspace
nominalViewing actions of a preview with restricted reads

A preview has restricted reads because the workspace is untrusted or the file is standalone. Each action below reaches its handler and has the outcome of the row.

Action (page message)Outcome in a preview with restricted reads
Theme button (previewThemeModeChanged)the mode is stored for the workspace, no error is shown
Zoom in (zoom preference of previewViewPreferenceChanged)the zoom is stored for the workspace and applied to the next page
Table of contents button (previewViewPreferenceChanged)the host stores the toc preference
Back and Next (previewHistoryGo)the previous or next document opens, for a file outside the workspace with a history of two places
Follow a link to a sibling Markdown file (previewLink)the file opens
Ask about a visible relative link (previewLinkDiscover)the host answers with the target or the reason
Copy code (previewCopyText)the requested code text is on the clipboard and the document is unchanged
Label list (previewListTargets)answered from the document text, as with full reads
nominalThe dispatcher stops no request for trust
Givena preview with restricted reads
Whenthe page sends previewEditOpen, previewViewPreferenceChanged, previewHistoryGo, previewLink or previewLinkDiscover
Theneach reaches the handler of its type; a theme message stays accepted while an edit request is handled (see SwRS-MDOKFSTUDIO-TRUST-005)
refusalThe citation list needs a trusted workspace folder
Givena preview with restricted reads
Whenthe page sends previewListCitations for the current render
Thenthe host answers ok false with "Listing citations searches the workspace for .bib files, which needs a trusted workspace folder that holds this file." and reads no file; the label list (previewListTargets) is answered from the document text
refusalReasons that do not depend on trust
InputOutcome
A write request that names an older renderAnswered with the out-of-date reason, or dropped for a message of another document (see SwRS-MDOKFSTUDIO-TRUST-065)
A write while a Markdown edit is open on the host sideRefused with "Save or cancel the open Markdown edit ..."
A document that is not a saved fileRefused (for example "Save the document before pasting an image.")
A file that VS Code holds read-only (files.readonlyInclude, or made read-only in the session)VS Code accepts the edit and writes nothing: every write above (the label rename, thread reply and delete, find and replace, block save, move, cut, paste and drop, checkbox toggle, metadata save) checks that the text changed and answers "This file is read-only in VS Code." instead of success (see SwRS-MDOKFSTUDIO-TRUST-001); a pasted image whose block save fails that way is deleted again
A malformed checkbox toggle or radio groupAnswered with "The checkbox request was not understood. Refresh the preview."
nominalHost-side writes follow the trust-free rule
InputOutcome
A preview with restricted reads switches documentA previewFlushEdit is posted, like for any preview
A document is saved and the only preview of it has restricted readsThe moved lines are written to the review comments file
previewThemeModeChanged or a zoom change with the old revision after a newer renderDropped by the render gate, as for a preview with full reads

Implemented in 8

Tested by 17

Replaces

SwRS-MDOKFSTUDIO-CODE-025Allow copying in read-only previews superseded superseded by SwRS-MDOKFSTUDIO-TRUST-005 Markdown file
SwRS-MDOKFSTUDIO-FMEDIT-051A save in an untrusted workspace is refused superseded superseded by SwRS-MDOKFSTUDIO-TRUST-005 Markdown file
SwRS-MDOKFSTUDIO-GFM-026Read-only previews disable checkboxes superseded superseded by SwRS-MDOKFSTUDIO-TRUST-005 Markdown file
SwRS-MDOKFSTUDIO-MYST-042The host refuses a rename in an untrusted or read-only preview superseded superseded by SwRS-MDOKFSTUDIO-TRUST-005 Markdown file
SwRS-MDOKFSTUDIO-TRUST-006A preview with restricted reads keeps every viewing action superseded superseded by SwRS-MDOKFSTUDIO-TRUST-005 Markdown file