Skip to content

feat: fix FileAdapter CSV format to preserve spaces after commas#407

Merged
hsluoyz merged 2 commits intomasterfrom
copilot/fix-ci-error
Dec 19, 2025
Merged

feat: fix FileAdapter CSV format to preserve spaces after commas#407
hsluoyz merged 2 commits intomasterfrom
copilot/fix-ci-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 19, 2025

fix: #406

Tests were failing because FileAdapter::save_policy wrote CSV files without spaces after commas (p, alice,data1,read), while the original files had spaces (p, alice, data1, read). Tests with auto-save enabled modified shared example files, causing subsequent tests to fail on policy loading.

Changes:

  • Updated FileAdapter::save_policy to use rule.join(", ") instead of rule.join(",") for both policy and grouping sections
  • Strip trailing newline from generated CSV to match source file format
// Before
writeln!(policies, "{}, {}", ptype, rule.join(","))

// After  
writeln!(policies, "{}, {}", ptype, rule.join(", "))
// ...
if policies.ends_with('\n') {
    policies.pop();
}

This ensures policy files remain byte-identical after save operations, preventing test interference.

Original prompt

This section details on the original issue you should resolve

<issue_title>[bug] fix CI error</issue_title>
<issue_description>see: https://github.com/casbin/casbin-rs/actions/runs/20377041315/job/58558208590#step:13:220

[Auto Build CI (ubuntu-latest, beta)](https://github.com/casbin/casbin-rs/actions/runs/20377041315/job/58558208590#logs)
failed 18 minutes ago in 1m 49s

Cargo Test For All Features Using tokio

Run actions-rs/cargo@v1
/home/runner/.cargo/bin/cargo test --no-default-features --features runtime-tokio,cached,glob,ip,watcher,logging,incremental,explain
   Compiling casbin ***.17.0 (/home/runner/work/casbin-rs/casbin-rs)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 6.09s
     Running unittests src/lib.rs (target/debug/deps/casbin-af3cc61c528878e1)

running 101 tests
test adapter::string_adapter::tests::test_save_policy ... ok
test adapter::string_adapter::tests::test_clear_policy ... ok
test adapter::string_adapter::tests::test_is_filtered ... ok
test cache::default_cache::tests::test_has_and_clear ... ok
test cache::default_cache::tests::test_set_and_get ... ok
test cached_enforcer::tests::test_send_sync ... ok
test config::tests::test_from_text ... ok
test config::tests::test_get ... ok
test enforcer::tests::test_custom_function_with_dynamic_types ... ok
test adapter::string_adapter::tests::test_load_policy ... ok
test enforcer::tests::test_enable_auto_save ... ok
test enforcer::tests::test_enforcer_swap_adapter_type ... ok
test enforcer::tests::test_filtered_file_adapter ... ok
test enforcer::tests::test_enforce_ex ... FAILED
test enforcer::tests::test_ip_match_model ... ok
test enforcer::tests::test_get_and_set_model ... ok
test enforcer::tests::test_key_match_model_in_memory_deny ... ok
test enforcer::tests::test_get_and_set_adapter_in_mem ... ok
test enforcer::tests::test_not_used_rbac_model_in_memory ... ok
test enforcer::tests::test_policy_abac1 ... ok
test enforcer::tests::test_keymatch_custom_model ... ok
test enforcer::tests::test_key_match_model_in_memory ... ok
test enforcer::tests::test_policy_abac2 ... ok
test enforcer::tests::test_send_sync ... ok
test enforcer::tests::test_rbac_model_in_memory ... ok
test enforcer::tests::test_rbac_model_in_memory_indeterminate ... ok
test error::tests::test_send_sync ... ok
test enforcer::tests::test_role_links ... ok
test management_api::tests::test_get_list ... FAILED
test enforcer::tests::test_set_role_manager ... ok
test frontend::tests::test_casbin_js_get_permission_for_user ... ok
test management_api::tests::test_get_policy_api ... FAILED
test management_api::tests::test_modify_grouping_policy_api ... FAILED
test management_api::tests::test_modify_grouping_policies_api ... FAILED
test management_api::tests::test_modify_policies_api ... FAILED
test model::default_model::tests::test_abac ... ok
test model::default_model::tests::test_basic_model ... ok
test management_api::tests::test_modify_policy_api ... FAILED
test model::default_model::tests::test_basic_model_no_policy ... ok
test model::default_model::tests::test_basic_model_with_root ... ok
test model::default_model::tests::test_basic_model_without_resources ... ok
test model::default_model::tests::test_basic_model_with_root_no_policy ... ok
test model::default_model::tests::test_basic_model_without_users ... ok
test model::default_model::tests::test_rbac_model_using_in_op ... FAILED
test model::default_model::tests::test_rbac_model_with_custom_data ... FAILED
test model::default_model::tests::test_rbac_model ... FAILED
test model::default_model::tests::test_rbac_model_with_deny ... ok
test model::default_model::tests::test_rbac_model_with_domains_at_runtime_mock_adapter ... ok
test model::default_model::tests::test_rbac_model_with_not_deny ... ok
test model::default_model::tests::test_rbac_model_with_domains ... ok
test model::function_map::tests::test_glob_match ... ok
test model::default_model::tests::test_rbac_model_with_domains_runtime ... ok
test model::function_map::tests::test_ip_match_panic_1 - should panic ... ok
test model::function_map::tests::test_key_get ... ok
test model::function_map::tests::test_ip_match ... ok
test model::function_map::tests::test_ip_match_panic_2 - should panic ... ok
test model::default_model::tests::test_rbac_model_with_resource_roles ... ok
test model::function_map::tests::test_key_match ... ok
test model::function_map::tests::test_key_match2 ... ok
test model::function_map::tests::test_key_match3 ... ok
test model::function_map::tests::test_key_match5 ... ok
test model::function_map::tests::test_regex_match ... ok
test rbac::default_role_manager::matching_bfs::test::test_max_depth ... ok
test rbac::default_role_manager::tests::test_basic_role_matching ... ok
test rbac::default_role_manager::tests::test_basic_role_matching2 ... ok
test rbac::default_role_manager::tests::test_clear ... ok
test rbac::default_role_manager::tests::test_cross_domain_role_inheritance_complex ... ok
test rbac::default_role_manager...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes casbin/casbin-rs#406

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CI error in test suite Fix FileAdapter CSV format to preserve spaces after commas Dec 19, 2025
Copilot AI requested a review from hsluoyz December 19, 2025 17:42
@hsluoyz hsluoyz marked this pull request as ready for review December 19, 2025 17:49
@github-actions
Copy link
Copy Markdown

Benchmark for 7272c2a

Click to view benchmark
Test PR Benchmark Master Benchmark %
b_benchmark_rbac_model_large 9.7±0.03ms 10.1±0.08ms -3.96%
benchmark priority model 1471.8±15.80ns 1468.5±11.24ns +0.22%
benchmark_abac_model 1074.9±16.53ns 1098.5±13.15ns -2.15%
benchmark_basic_model 1217.7±37.03ns 1153.4±10.53ns +5.57%
benchmark_key_match 4.0±0.05µs 4.1±0.04µs -2.44%
benchmark_raw 0.0±0.00ns 0.0±0.00ns NaN%
benchmark_rbac_model 3.3±0.04µs 3.3±0.04µs 0.00%
benchmark_rbac_model_medium 819.9±35.21µs 785.5±5.37µs +4.38%
benchmark_rbac_model_with_domains 1996.2±32.09ns 2.1±0.02µs -4.94%
benchmark_rbac_with_deny 5.3±0.06µs 5.3±0.07µs 0.00%
benchmark_rbac_with_resource_roles 1485.8±23.15ns 1430.3±9.18ns +3.88%
benchmark_role_manager_large 4.2±0.02ms 4.2±0.01ms 0.00%
benchmark_role_manager_medium 268.3±4.32µs 268.5±4.14µs -0.07%
benchmark_role_manager_small 84.0±1.51µs 81.3±0.62µs +3.32%

@hsluoyz hsluoyz changed the title Fix FileAdapter CSV format to preserve spaces after commas feat: fix FileAdapter CSV format to preserve spaces after commas Dec 19, 2025
@hsluoyz hsluoyz merged commit e3762ec into master Dec 19, 2025
9 of 10 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (7272c2a) to head (8126594).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@      Coverage Diff      @@
##   master   #407   +/-   ##
=============================
=============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

github-actions bot pushed a commit that referenced this pull request Dec 19, 2025
# [2.18.0](v2.17.0...v2.18.0) (2025-12-19)

### Bug Fixes

* remove beta Rust version from CI ([#409](#409)) ([f22f84c](f22f84c))
* remove irrelevant links in README ([7272c2a](7272c2a))

### Features

* fix FileAdapter CSV format to preserve spaces after commas ([#407](#407)) ([5d0a915](5d0a915))
@hsluoyz hsluoyz mentioned this pull request Dec 19, 2025
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.

[bug] fix CI error

3 participants