Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cicero-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lint": "eslint .",
"postlint": "npm run licchk",
"licchk": "license-check-and-add check -f ./license.config.json",
"test:mocha": "mocha --timeout 40000",
"test:mocha": "mocha --timeout 40000 --recursive",
"test:watch": "npm run test:mocha -- --watch",
"test:windows": "npm run test:mocha",
"test": "npm run test:mocha",
Expand Down
115 changes: 115 additions & 0 deletions packages/cicero-core/test/loaders/compositearchiveloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const CompositeArchiveLoader = require('../../src/loaders/compositearchiveloader');
const chai = require('chai');
const sinon = require('sinon');

chai.should();
chai.use(require('chai-as-promised'));

describe('CompositeArchiveLoader', () => {

let compositeLoader;
let mockLoader1;
let mockLoader2;

beforeEach(() => {
compositeLoader = new CompositeArchiveLoader();
// Create dummy loaders (The "Employees")
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The comment "The Employees" is unclear and doesn't add value to the test code. Consider removing it or replacing it with a more descriptive comment about what these mock loaders represent in the context of the CompositeArchiveLoader pattern.

Suggested change
// Create dummy loaders (The "Employees")
// Create mock archive loaders used by the CompositeArchiveLoader in these tests

Copilot uses AI. Check for mistakes.
mockLoader1 = {
accepts: sinon.stub(),
load: sinon.stub()
};
mockLoader2 = {
accepts: sinon.stub(),
load: sinon.stub()
};
Comment on lines +33 to +40
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Consider using simple mock objects instead of sinon stubs to avoid introducing a new dependency. The codebase uses mock-require for mocking (see httparchiveloader.js), and for this test case, plain JavaScript objects with methods would suffice. For example: mockLoader1 = { accepts: () => false, load: () => {} }. If you still prefer sinon for its assertion capabilities, make sure to add it to devDependencies.

Copilot uses AI. Check for mistakes.
});

describe('#constructor', () => {
it('should start with zero loaders', () => {
compositeLoader.getArchiveLoaders().should.have.lengthOf(0);
});
});

describe('#addArchiveLoader', () => {
it('should add loaders to the list', () => {
compositeLoader.addArchiveLoader(mockLoader1);
compositeLoader.getArchiveLoaders().should.have.lengthOf(1);
compositeLoader.addArchiveLoader(mockLoader2);
compositeLoader.getArchiveLoaders().should.have.lengthOf(2);
});
});

describe('#clearArchiveLoaders', () => {
it('should remove all loaders', () => {
compositeLoader.addArchiveLoader(mockLoader1);
compositeLoader.clearArchiveLoaders();
compositeLoader.getArchiveLoaders().should.have.lengthOf(0);
});
});

describe('#accepts', () => {
it('should return true if one of the loaders accepts the URL', () => {
// Mock: Loader 1 says NO, Loader 2 says YES
mockLoader1.accepts.returns(false);
mockLoader2.accepts.returns(true);
compositeLoader.addArchiveLoader(mockLoader1);
compositeLoader.addArchiveLoader(mockLoader2);

const result = compositeLoader.accepts('http://test.url');
result.should.be.true;
});

it('should return false if NONE of the loaders accept the URL', () => {
mockLoader1.accepts.returns(false);
mockLoader2.accepts.returns(false);
compositeLoader.addArchiveLoader(mockLoader1);
compositeLoader.addArchiveLoader(mockLoader2);

const result = compositeLoader.accepts('http://test.url');
result.should.be.false;
});
});
Comment on lines +66 to +87
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Missing test case to verify early exit behavior when the first loader accepts the URL. Add a test where mockLoader1.accepts returns true to ensure that mockLoader2.accepts is never called, demonstrating the early exit optimization in the accepts method.

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +87
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Missing test case for the accepts method when there are no loaders registered. This should verify that accepts returns false when the loaders array is empty, ensuring the edge case of an uninitialized CompositeArchiveLoader is handled correctly.

Copilot uses AI. Check for mistakes.

describe('#load', () => {
it('should delegate load to the first accepting loader', async () => {
mockLoader1.accepts.returns(false);
mockLoader2.accepts.returns(true);
mockLoader2.load.resolves('ARCHIVE_DATA'); // Simulate successful load

compositeLoader.addArchiveLoader(mockLoader1);
compositeLoader.addArchiveLoader(mockLoader2);

const result = await compositeLoader.load('http://test.url', {});
result.should.equal('ARCHIVE_DATA');
sinon.assert.calledWith(mockLoader2.load, 'http://test.url', {});
});

it('should throw an error if NO loader accepts the URL', () => {
mockLoader1.accepts.returns(false);
mockLoader2.accepts.returns(false);

compositeLoader.addArchiveLoader(mockLoader1);
compositeLoader.addArchiveLoader(mockLoader2);

(() => {
compositeLoader.load('http://unknown.url', {});
}).should.throw(/Failed to find a model file loader/);
});
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Missing test case for the load method when there are no loaders registered. This should verify that load throws an error when the loaders array is empty, ensuring the edge case of an uninitialized CompositeArchiveLoader is handled correctly.

Suggested change
});
});
it('should throw an error if there are no loaders registered', () => {
(() => {
compositeLoader.load('http://empty.url', {});
}).should.throw(/Failed to find a model file loader/);
});

Copilot uses AI. Check for mistakes.
});
Comment on lines +89 to +114
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Missing test case for the load method when the first loader accepts the URL. Add a test where mockLoader1.accepts returns true to ensure that mockLoader1.load is called and mockLoader2 is never checked, demonstrating the early exit optimization in the load method.

Copilot uses AI. Check for mistakes.
});
Loading