Skip to content

Conversation

@Huggin423
Copy link
Contributor

fix #506

@CLAassistant
Copy link

CLAassistant commented Jan 6, 2026

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

coveralls commented Jan 6, 2026

Pull Request Test Coverage Report for Build 20748193976

Details

  • 4 of 62 (6.45%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.7%) to 75.579%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/managementEnforcer.ts 0 7 0.0%
src/internalEnforcer.ts 4 55 7.27%
Totals Coverage Status
Change from base Build 20679550322: -2.7%
Covered Lines: 1645
Relevant Lines: 2053

💛 - Coveralls

@Huggin423 Huggin423 force-pushed the fix/506-bypass-adapter-loop branch 2 times, most recently from f08c0a4 to e68147f Compare January 6, 2026 05:52
@hsluoyz hsluoyz requested a review from Copilot January 6, 2026 05:56
Copy link

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 fixes an infinite loop issue (#506) in watchers by adding a useAdapter parameter to internal policy management methods. When set to false, this parameter prevents adapter calls, which is crucial for the self* methods that are called from watchers to avoid triggering recursive adapter updates.

Key Changes

  • Added optional useAdapter parameter (defaults to true) to seven internal methods in InternalEnforcer
  • Updated all self* methods in ManagementEnforcer to pass false for both useWatcher and useAdapter parameters
  • Modified adapter conditional checks to include the new useAdapter flag

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 15 comments.

File Description
src/internalEnforcer.ts Added useAdapter parameter with default value true to seven internal methods and updated adapter conditional checks to respect this flag
src/managementEnforcer.ts Updated six self* methods to pass false for the new useAdapter parameter

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

}

if (this.adapter && this.autoSave) {
// if (this.adapter && this.autoSave) {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Remove commented-out code. The old condition is no longer needed since the new condition with useAdapter is now in place.

Copilot uses AI. Check for mistakes.
this.fm.addFunction(name, func);
}

// add fifth argument
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

This comment is vague and unhelpful. Consider replacing it with a more descriptive comment explaining why the useAdapter parameter is needed, such as "Pass useAdapter=false to prevent infinite loops when called from watchers".

Suggested change
// add fifth argument
// Wrapper around addPolicyInternal that passes useAdapter=false (final argument)
// to prevent infinite update loops when invoked from watchers.

Copilot uses AI. Check for mistakes.
Comment on lines 64 to 70
protected async addPoliciesInternal(
sec: string,
ptype: string,
rules: string[][],
useWatcher: boolean,
useAdapter = true
): Promise<boolean> {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Add JSDoc parameter documentation for the new useAdapter parameter to explain its purpose. For example: "@param useAdapter whether to use the adapter for persistence (set to false to avoid infinite loops in watchers)".

Copilot uses AI. Check for mistakes.
Comment on lines 115 to 114
protected async addPoliciesInternalEx(
sec: string,
ptype: string,
rules: string[][],
useWatcher: boolean,
useAdapter = true
): Promise<boolean> {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Add JSDoc parameter documentation for the new useAdapter parameter to explain its purpose. For example: "@param useAdapter whether to use the adapter for persistence (set to false to avoid infinite loops in watchers)".

Copilot uses AI. Check for mistakes.
Comment on lines 255 to 251
protected async removePoliciesInternal(
sec: string,
ptype: string,
rules: string[][],
useWatcher: boolean,
useAdapter = true
): Promise<boolean> {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Add JSDoc parameter documentation for the new useAdapter parameter to explain its purpose. For example: "@param useAdapter whether to use the adapter for persistence (set to false to avoid infinite loops in watchers)".

Copilot uses AI. Check for mistakes.
*/
export class InternalEnforcer extends CoreEnforcer {
/**
* addPolicyInternal adds a rule to the current policy.
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Add JSDoc parameter documentation for the new useAdapter parameter to explain its purpose. For example: "@param useAdapter whether to use the adapter for persistence (set to false to avoid infinite loops in watchers)".

Suggested change
* addPolicyInternal adds a rule to the current policy.
* addPolicyInternal adds a rule to the current policy.
*
* @param useAdapter whether to use the adapter for persistence (set to false to avoid infinite loops in watchers)

Copilot uses AI. Check for mistakes.
Comment on lines 214 to 211
protected async removePolicyInternal(
sec: string,
ptype: string,
rule: string[],
useWatcher: boolean,
useAdapter = true
): Promise<boolean> {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Add JSDoc parameter documentation for the new useAdapter parameter to explain its purpose. For example: "@param useAdapter whether to use the adapter for persistence (set to false to avoid infinite loops in watchers)".

Copilot uses AI. Check for mistakes.
}

if (this.adapter && this.autoSave) {
// if (this.adapter && this.autoSave) {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Remove commented-out code. The old condition is no longer needed since the new condition with useAdapter is now in place.

Suggested change
// if (this.adapter && this.autoSave) {

Copilot uses AI. Check for mistakes.
}

if (this.autoSave) {
// if (this.autoSave) {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Remove commented-out code. The old condition is no longer needed since the new condition with useAdapter is now in place.

Suggested change
// if (this.autoSave) {

Copilot uses AI. Check for mistakes.
useAdapter = true
): Promise<boolean> {
if (this.adapter && this.autoSave) {
// if (this.adapter && this.autoSave) {
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

Remove commented-out code. The old condition is no longer needed since the new condition with useAdapter is now in place.

Copilot uses AI. Check for mistakes.
@Huggin423 Huggin423 force-pushed the fix/506-bypass-adapter-loop branch from e68147f to 75165bd Compare January 6, 2026 10:21
@Huggin423 Huggin423 force-pushed the fix/506-bypass-adapter-loop branch from 75165bd to c64e7a6 Compare January 6, 2026 10:41
@Huggin423 Huggin423 closed this Jan 6, 2026
@hsluoyz
Copy link
Member

hsluoyz commented Jan 6, 2026

replaced by: #539

@hsluoyz hsluoyz reopened this Jan 6, 2026
@hsluoyz hsluoyz closed this Jan 6, 2026
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.

Feature request: Methods in enforcer for adding, updating and deleting policies without usage of adapter (even if autoSave is true)

4 participants