Skip to content

Comments

Should not be able to edit file def instance in code mode#4025

Open
FadhlanR wants to merge 2 commits intomainfrom
cs-10065-prevent-editing-file-def-instance
Open

Should not be able to edit file def instance in code mode#4025
FadhlanR wants to merge 2 commits intomainfrom
cs-10065-prevent-editing-file-def-instance

Conversation

@FadhlanR
Copy link
Contributor

@FadhlanR FadhlanR commented Feb 19, 2026

Previously, a file was set to read-only in code mode only if the user lacked write permissions and the file was binary. In this PR, I added a check for whether the file is a fileDef instance, if it is, the file is now marked as read-only.

@github-actions
Copy link

Preview deployments

@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   1h 43m 2s ⏱️ + 2m 55s
1 857 tests +1  1 843 ✅ +1  14 💤 ±0  0 ❌ ±0 
1 872 runs  +1  1 858 ✅ +1  14 💤 ±0  0 ❌ ±0 

Results for commit 546400f. ± Comparison against base commit 8d45ff7.

♻️ This comment has been updated with latest results.

@FadhlanR FadhlanR marked this pull request as ready for review February 20, 2026 07:56
@FadhlanR FadhlanR requested review from a team and lukemelia February 20, 2026 07:56
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 546400fad0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 646 to +647
get isReadOnly() {
return !this.realm.canWrite(this.readyFile.url);
return !this.realm.canWrite(this.readyFile.url) || this.isFileDefInstance;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark file-def files read-only while metadata is loading

For writable realms, isReadOnly remains false until the async store.get(fileUrl, { type: 'file-meta' }) call finishes and sets fileDefResource.value, so a file-def instance can briefly open as editable; on slower responses, users can type (and potentially trigger autosave) before the lock engages. This undermines the new guarantee that file-def instances are not editable in code mode.

Useful? React with 👍 / 👎.

return state;
});

private get isFileDefInstance() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this existing function? Can it be used here?

export function isFileDefInstance<T extends FileDef>(
fileInstance: any,

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes file definition instances read-only in code mode by adding a check to determine if an opened file is a FileDef instance. Previously, files were only marked as read-only based on user write permissions and binary file status.

Changes:

  • Added resource to asynchronously load file metadata and check if file is a FileDef instance
  • Modified isReadOnly getter to include FileDef instance check
  • Added test to verify FileDef instances are read-only in code mode

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/host/app/components/operator-mode/code-submode.gts Added fileDefResource to load file metadata, isFileDefInstance getter, and updated isReadOnly to check for FileDef instances
packages/host/tests/acceptance/code-submode/file-def-navigation-test.gts Added test verifying that FileDef instances show read-only indicators and hide edit format options

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


get isReadOnly() {
return !this.realm.canWrite(this.readyFile.url);
return !this.realm.canWrite(this.readyFile.url) || this.isFileDefInstance;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isReadOnly getter may briefly return false while the fileDefResource is still loading, potentially allowing users to start editing before the file is marked as read-only. Consider also checking the loading state to ensure the file is read-only during the resource fetch. For example: return !this.realm.canWrite(this.readyFile.url) || this.isFileDefInstance || this.fileDefResource?.isLoading;

Suggested change
return !this.realm.canWrite(this.readyFile.url) || this.isFileDefInstance;
return (
!this.realm.canWrite(this.readyFile.url) ||
this.isFileDefInstance ||
this.fileDefResource?.isLoading
);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants