From 8b6bddf1ddbe7aa677e79e676ded99fabe4ea7ae Mon Sep 17 00:00:00 2001 From: Mike Christopher Date: Wed, 21 Aug 2024 16:06:11 -0700 Subject: [PATCH 1/6] feat: update security policy --- SECURITY.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000000..dab1c5c4c2c --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,31 @@ +# Fuel Security Policy + +Thank you for helping make the Fuel ecosystem safe for everyone. The Fuel team take security bugs very seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. + +## Reporting Security Issues + +If you believe you have found a security vulnerability in any Fuel-owned repository, please report it to us through coordinated disclosure. + +**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.** + +Instead, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/FuelLabs/sway/security/advisories/new) tab. + +The Fuel team will send a response indicating the next steps in handling your report. After the initial reply to your report, the team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. + +Please include as much of the information listed below as you can to help us better understand and resolve the issue: + +* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting) +* Full paths of source file(s) related to the manifestation of the issue +* The location of the affected source code (tag/branch/commit or direct URL) +* Any special configuration required to reproduce the issue +* Step-by-step instructions to reproduce the issue +* Proof-of-concept or exploit code (if possible) +* Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +Report security bugs in third-party modules to the person or team maintaining the module. + +## Non-Security Issues + +If the issue is not security-related, please report it publicly by opening a [GitHub Issue](https://github.com/FuelLabs/sway/issues/new). From ae9a8a9e04436154a73f97d4c756c2f020964699 Mon Sep 17 00:00:00 2001 From: Daniel Frederico Lins Leite Date: Thu, 22 Aug 2024 11:33:59 +0100 Subject: [PATCH 2/6] Fix sway templates (#6446) ## Description ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. --- .github/workflows/ci.yml | 67 ++++++++++--------- .../template/Cargo.toml | 2 +- .../sway-script-test-rs/template/Cargo.toml | 2 +- templates/sway-test-rs/template/Cargo.toml | 2 +- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76640ea54f7..85917e5daba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,7 +146,7 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - + - name: Set up Rust uses: actions-rs/toolchain@v1 with: @@ -194,7 +194,7 @@ jobs: - name: Run mdbook build uses: peaceiris/actions-mdbook@v1 with: - mdbook-version: '0.4.25' + mdbook-version: "0.4.25" - name: Emit book logs to tmp.txt, fail if build logs contain 'ERROR' run: | MDBOOK_preprocessor__FORC_documenter__STRICT="true" mdbook build docs/book 2>&1 | tee tmp.txt @@ -243,6 +243,7 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.RUST_VERSION }} + targets: wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 - name: Install Forc run: cargo install --locked --debug --path ./forc @@ -257,6 +258,8 @@ jobs: # run: (cd test-proj && forc test) - name: Install cargo-generate run: cargo install --locked cargo-generate + - name: Install fuel-core + run: cargo install --locked fuel-core-bin - name: Generate Rust Integration Tests run: (cd test-proj && cargo generate --init --path ../templates/sway-test-rs --name test-proj) - name: Update project cargo manifest with workspace @@ -276,10 +279,10 @@ jobs: with: toolchain: ${{ env.RUST_VERSION }} - uses: Swatinem/rust-cache@v2 - - name: 'Build Workspace' + - name: "Build Workspace" run: cargo build --locked --workspace --all-features --all-targets env: - RUSTFLAGS: '-D warnings' + RUSTFLAGS: "-D warnings" cargo-clippy: runs-on: ubuntu-latest @@ -306,7 +309,7 @@ jobs: uses: baptiste0928/cargo-install@v1 with: crate: cargo-toml-lint - version: '0.1' + version: "0.1" - name: Run Cargo.toml linter run: git ls-files | grep Cargo.toml$ | grep -v 'templates/' | xargs --verbose -n 1 cargo-toml-lint @@ -341,7 +344,7 @@ jobs: mv fuel-core-${{ needs.get-fuel-core-version.outputs.fuel_core_version }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core - name: Cargo Run E2E Tests (Fuel VM) run: | - fuel-core run --db-type in-memory --debug & + fuel-core run --db-type in-memory --debug & sleep 5 && cargo run --locked --release --bin test -- --locked @@ -364,7 +367,7 @@ jobs: mv fuel-core-${{ needs.get-fuel-core-version.outputs.fuel_core_version }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core - name: Cargo Run E2E Tests (Fuel VM) run: | - fuel-core run --db-type in-memory --debug & + fuel-core run --db-type in-memory --debug & sleep 5 && cargo run --locked --release --bin test -- --locked --release @@ -446,8 +449,8 @@ jobs: run: ./benchmark.sh --prepare-for-commit - uses: EndBug/add-and-commit@v9 with: - cwd: './performance-data' - message: 'Updated benchmark data' + cwd: "./performance-data" + message: "Updated benchmark data" default_author: github_actions forc-unit-tests: @@ -598,10 +601,10 @@ jobs: with: status: ${{ job.status }} token: ${{ secrets.GITHUB_TOKEN }} - notification_title: '{workflow} has {status_message}' - message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>' - footer: '' - notify_when: 'failure' + notification_title: "{workflow} has {status_message}" + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + footer: "" + notify_when: "failure" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }} @@ -625,7 +628,7 @@ jobs: ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc/Cargo.toml ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-pkg/Cargo.toml ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-plugins/forc-client/Cargo.toml - ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-plugins/forc-debug/Cargo.toml + ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-plugins/forc-debug/Cargo.toml ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-plugins/forc-doc/Cargo.toml ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-plugins/forc-fmt/Cargo.toml ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-plugins/forc-lsp/Cargo.toml @@ -651,10 +654,10 @@ jobs: with: status: ${{ job.status }} token: ${{ secrets.GITHUB_TOKEN }} - notification_title: '{workflow} has {status_message}' - message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>' - footer: '' - notify_when: 'failure' + notification_title: "{workflow} has {status_message}" + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + footer: "" + notify_when: "failure" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }} @@ -701,10 +704,10 @@ jobs: with: status: ${{ job.status }} token: ${{ secrets.GITHUB_TOKEN }} - notification_title: '{workflow} has {status_message}' - message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>' - footer: '' - notify_when: 'failure' + notification_title: "{workflow} has {status_message}" + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + footer: "" + notify_when: "failure" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }} @@ -778,10 +781,10 @@ jobs: with: status: ${{ job.status }} token: ${{ secrets.GITHUB_TOKEN }} - notification_title: '{workflow} has {status_message}' - message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>' - footer: '' - notify_when: 'failure' + notification_title: "{workflow} has {status_message}" + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + footer: "" + notify_when: "failure" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }} @@ -833,10 +836,10 @@ jobs: with: status: ${{ job.status }} token: ${{ secrets.GITHUB_TOKEN }} - notification_title: '{workflow} has {status_message}' - message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>' - footer: '' - notify_when: 'failure' + notification_title: "{workflow} has {status_message}" + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + footer: "" + notify_when: "failure" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }} @@ -881,13 +884,13 @@ jobs: - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - key: '${{ matrix.job.target }}' + key: "${{ matrix.job.target }}" - name: Use Cross uses: baptiste0928/cargo-install@v1 with: crate: cross - cache-key: '${{ matrix.job.target }}' + cache-key: "${{ matrix.job.target }}" - name: Build forc binaries run: | diff --git a/templates/sway-predicate-test-rs/template/Cargo.toml b/templates/sway-predicate-test-rs/template/Cargo.toml index 360e8b4b8c5..39f5f4d397e 100644 --- a/templates/sway-predicate-test-rs/template/Cargo.toml +++ b/templates/sway-predicate-test-rs/template/Cargo.toml @@ -7,7 +7,7 @@ authors = ["{{authors}}"] license = "Apache-2.0" [dev-dependencies] -fuels = { version = "0.66", features = ["fuel-core-lib"] } +fuels = "0.66.1" tokio = { version = "1.12", features = ["rt", "macros"] } [[test]] diff --git a/templates/sway-script-test-rs/template/Cargo.toml b/templates/sway-script-test-rs/template/Cargo.toml index 360e8b4b8c5..39f5f4d397e 100644 --- a/templates/sway-script-test-rs/template/Cargo.toml +++ b/templates/sway-script-test-rs/template/Cargo.toml @@ -7,7 +7,7 @@ authors = ["{{authors}}"] license = "Apache-2.0" [dev-dependencies] -fuels = { version = "0.66", features = ["fuel-core-lib"] } +fuels = "0.66.1" tokio = { version = "1.12", features = ["rt", "macros"] } [[test]] diff --git a/templates/sway-test-rs/template/Cargo.toml b/templates/sway-test-rs/template/Cargo.toml index c9d7d2d0661..39f5f4d397e 100644 --- a/templates/sway-test-rs/template/Cargo.toml +++ b/templates/sway-test-rs/template/Cargo.toml @@ -7,7 +7,7 @@ authors = ["{{authors}}"] license = "Apache-2.0" [dev-dependencies] -fuels = { version = "0.66.1", features = ["fuel-core-lib"] } +fuels = "0.66.1" tokio = { version = "1.12", features = ["rt", "macros"] } [[test]] From 5e0e3a4f8aba1171dcaeb236857c6be4f2ef70a4 Mon Sep 17 00:00:00 2001 From: Daniel Frederico Lins Leite Date: Thu, 22 Aug 2024 12:22:31 +0100 Subject: [PATCH 3/6] Guarantee only valid bools are being decoded (#6436) ## Description `AbiDecode` for `bool` was not checking for valid values allowing unsound bools that were not `true` nor `false`. Given that `3VL` is not within our scope here (:smile:), this PR will now `revert` in this case which is certainly a problem decoding values. The same thing already happens for `enum` variant, which also `revert(0)` when the variant is unknown. These two are the only cases where the "encoded bytes" can live outside of their respective valid set. ## Checklist - [ ] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --- sway-lib-core/src/codec.sw | 12 ++++++- .../json_abi_oracle_new_encoding.json | 32 +++++++++---------- .../storage_access_caller/src/main.sw | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/sway-lib-core/src/codec.sw b/sway-lib-core/src/codec.sw index 2b2489b16e8..2e9ed4aae20 100644 --- a/sway-lib-core/src/codec.sw +++ b/sway-lib-core/src/codec.sw @@ -2585,7 +2585,11 @@ impl AbiDecode for u8 { impl AbiDecode for bool { fn abi_decode(ref mut buffer: BufferReader) -> bool { - buffer.read::() + match buffer.read::() { + 0 => false, + 1 => true, + _ => __revert(0), + } } } @@ -5357,3 +5361,9 @@ fn ok_abi_encoding() { assert_eq(array[0], 255u8, 0); assert_eq(array[1], 254u8, 0); } + +#[test(should_revert)] +fn nok_abi_encoding_invalid_bool() { + let actual = encode(2u8); + let _ = abi_decode::(actual); +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json index fb14cd4d3c7..c7ff882e97c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json @@ -62,82 +62,82 @@ { "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", "name": "BOOL", - "offset": 7400 + "offset": 7432 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "U8", - "offset": 7592 + "offset": 7624 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "ANOTHER_U8", - "offset": 7328 + "offset": 7360 }, { "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", "name": "U16", - "offset": 7536 + "offset": 7568 }, { "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", "name": "U32", - "offset": 7576 + "offset": 7608 }, { "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", "name": "U64", - "offset": 7584 + "offset": 7616 }, { "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", "name": "U256", - "offset": 7544 + "offset": 7576 }, { "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", "name": "B256", - "offset": 7368 + "offset": 7400 }, { "concreteTypeId": "81fc10c4681a3271cf2d66b2ec6fbc8ed007a442652930844fcf11818c295bff", "name": "CONFIGURABLE_STRUCT", - "offset": 7488 + "offset": 7520 }, { "concreteTypeId": "a2922861f03be8a650595dd76455b95383a61b46dd418f02607fa2e00dc39d5c", "name": "CONFIGURABLE_ENUM_A", - "offset": 7408 + "offset": 7440 }, { "concreteTypeId": "a2922861f03be8a650595dd76455b95383a61b46dd418f02607fa2e00dc39d5c", "name": "CONFIGURABLE_ENUM_B", - "offset": 7448 + "offset": 7480 }, { "concreteTypeId": "4926d35d1a5157936b0a29bc126b8aace6d911209a5c130e9b716b0c73643ea6", "name": "ARRAY_BOOL", - "offset": 7336 + "offset": 7368 }, { "concreteTypeId": "776fb5a3824169d6736138565fdc20aad684d9111266a5ff6d5c675280b7e199", "name": "ARRAY_U64", - "offset": 7344 + "offset": 7376 }, { "concreteTypeId": "c998ca9a5f221fe7b5c66ae70c8a9562b86d964408b00d17f883c906bc1fe4be", "name": "TUPLE_BOOL_U64", - "offset": 7520 + "offset": 7552 }, { "concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a", "name": "STR_4", - "offset": 7512 + "offset": 7544 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "NOT_USED", - "offset": 7504 + "offset": 7536 } ], "encodingVersion": "1", diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw index f720cbddea9..aa4a3e1f59b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw @@ -6,7 +6,7 @@ use std::hash::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x3bc28acd66d327b8c1b9624c1fabfc07e9ffa1b5d71c2832c3bfaaf8f4b805e9; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xa6026cfed3ba7a4ab3aa17908da17248f0489c042acc7ffaefb8b6c6536b069a; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release +const CONTRACT_ID = 0xe4d312c5acc2982abb501d0baec18fe10ec1e8f7d68ae9dc1e8c92482a0c1d85; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release fn main() -> bool { let caller = abi(StorageAccess, CONTRACT_ID); From 5840e8dad37d2991b084a9456f1add708ff7795c Mon Sep 17 00:00:00 2001 From: Joshua Batty Date: Fri, 23 Aug 2024 05:31:04 +1000 Subject: [PATCH 4/6] Optimize manifest directory lookup with efficient caching (#6444) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Implemented a caching mechanism for manifest directory lookups using a DashMap. This optimization reduces average lookup time from approximately 421µs to 0.47µs, resulting in an 895x speed improvement for subsequent calls. part of #5445 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Co-authored-by: IGI-111 --- sway-lsp/src/server_state.rs | 39 +++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/sway-lsp/src/server_state.rs b/sway-lsp/src/server_state.rs index b50f546cf97..d448516105c 100644 --- a/sway-lsp/src/server_state.rs +++ b/sway-lsp/src/server_state.rs @@ -50,6 +50,7 @@ pub struct ServerState { pub(crate) cb_rx: Arc>, pub(crate) finished_compilation: Arc, pub(crate) pid_locked_files: PidLockedFiles, + manifest_cache: DashMap>, last_compilation_state: Arc>, } @@ -68,6 +69,7 @@ impl Default for ServerState { cb_rx: Arc::new(cb_rx), finished_compilation: Arc::new(Notify::new()), pid_locked_files: PidLockedFiles::new(), + manifest_cache: DashMap::new(), last_compilation_state: Arc::new(RwLock::new(LastCompilationState::Uninitialized)), }; // Spawn a new thread dedicated to handling compilation tasks @@ -351,19 +353,27 @@ impl ServerState { } async fn url_to_session(&self, uri: &Url) -> Result, LanguageServerError> { - let path = PathBuf::from(uri.path()); - let manifest = PackageManifestFile::from_dir(&path).map_err(|_| { - DocumentError::ManifestFileNotFound { - dir: path.to_string_lossy().to_string(), - } - })?; - - // strip Forc.toml from the path to get the manifest directory - let manifest_dir = manifest - .path() - .parent() - .ok_or(DirectoryError::ManifestDirNotFound)? - .to_path_buf(); + // Try to get the manifest directory from the cache + let manifest_dir = if let Some(cached_dir) = self.manifest_cache.get(uri) { + cached_dir.clone() + } else { + // Otherwise, find the manifest directory from the uri and cache it + let path = PathBuf::from(uri.path()); + let manifest = PackageManifestFile::from_dir(&path).map_err(|_| { + DocumentError::ManifestFileNotFound { + dir: path.to_string_lossy().to_string(), + } + })?; + let dir = Arc::new( + manifest + .path() + .parent() + .ok_or(DirectoryError::ManifestDirNotFound)? + .to_path_buf(), + ); + self.manifest_cache.insert(uri.clone(), dir.clone()); + dir + }; // If the session is already in the cache, return it if let Some(session) = self.sessions.get(&manifest_dir) { @@ -373,7 +383,8 @@ impl ServerState { // If no session can be found, then we need to call init and insert a new session into the map let session = Arc::new(Session::new()); session.init(uri, &self.documents).await?; - self.sessions.insert(manifest_dir.clone(), session.clone()); + self.sessions + .insert((*manifest_dir).clone(), session.clone()); Ok(session) } From d639739883ec43109f5a630deeb60e516161a15d Mon Sep 17 00:00:00 2001 From: Laisha Wadhwa Date: Fri, 23 Aug 2024 08:28:55 +0530 Subject: [PATCH 5/6] Updated the emitted event in the search page (#6454) ## Description Updated emitted event in the search page for forc-doc --------- Co-authored-by: Laisha Wadhwa Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Co-authored-by: Joshua Batty --- forc-plugins/forc-doc/src/render/search.rs | 4 ++-- .../forc-doc/src/tests/expects/impl_trait/mod.rs | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/forc-plugins/forc-doc/src/render/search.rs b/forc-plugins/forc-doc/src/render/search.rs index e0f84216ebe..9213c17210d 100644 --- a/forc-plugins/forc-doc/src/render/search.rs +++ b/forc-plugins/forc-doc/src/render/search.rs @@ -25,10 +25,10 @@ pub(crate) fn generate_searchbar(module_info: &ModuleInfo) -> Box const searchbar = document.getElementById("search-input"); const searchForm = document.getElementById("search-form"); searchbar.addEventListener("keyup", function(event) {{ - searchForm.dispatchEvent(new Event('submit')); + onSearchFormSubmit(event); }}); searchbar.addEventListener("search", function(event) {{ - searchForm.dispatchEvent(new Event('submit')); + onSearchFormSubmit(event); }}); function onQueryParamsChange() {{ diff --git a/forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs b/forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs index 5ab755043de..4699c55a6a9 100644 --- a/forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs +++ b/forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs @@ -37,10 +37,9 @@ fn test_impl_traits_default() { assert_index_html( &doc_path, project_name, - &expect![[ - r##"Bar in bar - Sway
pub struct Bar {}

Implementations

fn foo_bar()

Trait Implementations

fn foo()

something more about foo();

-

fn add(self, other: Self) -> Self

fn subtract(self, other: Self) -> Self

"## - ]], + &expect![[r##" + Bar in bar - Sway
pub struct Bar {}

Implementations

fn foo_bar()

Trait Implementations

fn foo()

something more about foo();

+

fn add(self, other: Self) -> Self

fn subtract(self, other: Self) -> Self

"##]], ); assert_search_js( &doc_path, @@ -195,7 +194,7 @@ fn test_impl_traits_no_deps() { &doc_path, project_name, &expect![[ - r##"Bar in bar - Sway
pub struct Bar {}

Implementations

fn foo_bar()

Trait Implementations

fn foo()

something more about foo();

+ r##"Bar in bar - Sway
pub struct Bar {}

Implementations

fn foo_bar()

Trait Implementations

fn foo()

something more about foo();

fn add(self, other: Self) -> Self

fn subtract(self, other: Self) -> Self

"## ]], ); From 72eb9246f21ad20053cc9459a7cb8ca6abb89cf7 Mon Sep 17 00:00:00 2001 From: Joshua Batty Date: Fri, 23 Aug 2024 13:38:13 +1000 Subject: [PATCH 6/6] Add `RUST_BACKTRACE: full` to lsp CI tests (#6457) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This will help when trying to debug why LSP tests are failing everynow and then in CI, such as [this run](https://github.com/FuelLabs/sway/actions/runs/10517913492/job/29142891731?pr=6454). closes #6456 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. Co-authored-by: Kaya Gökalp --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85917e5daba..aa6c9055cdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -549,6 +549,8 @@ jobs: toolchain: ${{ env.RUST_VERSION }} - uses: Swatinem/rust-cache@v2 - name: Run sway-lsp tests sequentially + env: + RUST_BACKTRACE: full run: cargo test --locked --release -p sway-lsp -- --nocapture --test-threads=1 cargo-test-workspace: runs-on: ubuntu-latest