@bryan-thompson/inspector-assessment-cli 1.30.1 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/__tests__/flag-parsing.test.js +195 -0
- package/build/lib/__tests__/cli-parserSchemas.test.js +553 -0
- package/build/lib/__tests__/zodErrorFormatter.test.js +282 -0
- package/build/lib/assessment-runner/__tests__/server-configSchemas.test.js +394 -0
- package/build/lib/assessment-runner/assessment-executor.js +4 -0
- package/build/lib/assessment-runner/config-builder.js +9 -0
- package/build/lib/assessment-runner/server-configSchemas.js +122 -0
- package/build/lib/cli-parser.js +23 -25
- package/build/lib/cli-parserSchemas.js +231 -0
- package/build/lib/zodErrorFormatter.js +91 -0
- package/package.json +1 -1
|
@@ -644,3 +644,198 @@ describe("Version Flag Parsing", () => {
|
|
|
644
644
|
});
|
|
645
645
|
});
|
|
646
646
|
});
|
|
647
|
+
/**
|
|
648
|
+
* Issue #118: Zod Schema Integration Tests
|
|
649
|
+
*
|
|
650
|
+
* Tests the integration between parseArgs() and Zod schema validation.
|
|
651
|
+
* Verifies that CLI arguments are validated through Zod schemas before
|
|
652
|
+
* being accepted into the options object.
|
|
653
|
+
*/
|
|
654
|
+
describe("parseArgs Zod Schema Integration", () => {
|
|
655
|
+
// Store original process.exit to mock it
|
|
656
|
+
let processExitSpy;
|
|
657
|
+
let consoleErrorSpy;
|
|
658
|
+
beforeEach(() => {
|
|
659
|
+
// Use fake timers to handle setTimeout in cli-parser error paths
|
|
660
|
+
jest.useFakeTimers();
|
|
661
|
+
// Mock process.exit to prevent actual exit
|
|
662
|
+
processExitSpy = jest
|
|
663
|
+
.spyOn(process, "exit")
|
|
664
|
+
.mockImplementation((() => { }));
|
|
665
|
+
// Mock console.error to capture error messages
|
|
666
|
+
consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(() => { });
|
|
667
|
+
});
|
|
668
|
+
afterEach(() => {
|
|
669
|
+
// Run any pending timers and restore
|
|
670
|
+
jest.runAllTimers();
|
|
671
|
+
jest.useRealTimers();
|
|
672
|
+
processExitSpy.mockRestore();
|
|
673
|
+
consoleErrorSpy.mockRestore();
|
|
674
|
+
});
|
|
675
|
+
describe("LogLevelSchema integration", () => {
|
|
676
|
+
it("parseArgs validates log level with LogLevelSchema", () => {
|
|
677
|
+
const result = parseArgs([
|
|
678
|
+
"test-server",
|
|
679
|
+
"--config",
|
|
680
|
+
"config.json",
|
|
681
|
+
"--log-level",
|
|
682
|
+
"debug",
|
|
683
|
+
]);
|
|
684
|
+
expect(result.logLevel).toBe("debug");
|
|
685
|
+
});
|
|
686
|
+
it("parseArgs rejects invalid log level via LogLevelSchema", () => {
|
|
687
|
+
const result = parseArgs([
|
|
688
|
+
"test-server",
|
|
689
|
+
"--config",
|
|
690
|
+
"config.json",
|
|
691
|
+
"--log-level",
|
|
692
|
+
"invalid-level",
|
|
693
|
+
]);
|
|
694
|
+
// Should set helpRequested and exit
|
|
695
|
+
expect(result.helpRequested).toBe(true);
|
|
696
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Invalid log level"));
|
|
697
|
+
});
|
|
698
|
+
it("accepts all valid log levels: silent, error, warn, info, debug", () => {
|
|
699
|
+
const validLevels = ["silent", "error", "warn", "info", "debug"];
|
|
700
|
+
for (const level of validLevels) {
|
|
701
|
+
consoleErrorSpy.mockClear();
|
|
702
|
+
const result = parseArgs([
|
|
703
|
+
"test-server",
|
|
704
|
+
"--config",
|
|
705
|
+
"config.json",
|
|
706
|
+
"--log-level",
|
|
707
|
+
level,
|
|
708
|
+
]);
|
|
709
|
+
expect(result.logLevel).toBe(level);
|
|
710
|
+
expect(result.helpRequested).toBeFalsy();
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
describe("ReportFormatSchema integration", () => {
|
|
715
|
+
it("parseArgs validates report format with ReportFormatSchema", () => {
|
|
716
|
+
const result = parseArgs([
|
|
717
|
+
"test-server",
|
|
718
|
+
"--config",
|
|
719
|
+
"config.json",
|
|
720
|
+
"--format",
|
|
721
|
+
"markdown",
|
|
722
|
+
]);
|
|
723
|
+
expect(result.format).toBe("markdown");
|
|
724
|
+
});
|
|
725
|
+
it("parseArgs accepts json format", () => {
|
|
726
|
+
const result = parseArgs([
|
|
727
|
+
"test-server",
|
|
728
|
+
"--config",
|
|
729
|
+
"config.json",
|
|
730
|
+
"--format",
|
|
731
|
+
"json",
|
|
732
|
+
]);
|
|
733
|
+
expect(result.format).toBe("json");
|
|
734
|
+
});
|
|
735
|
+
it("parseArgs rejects invalid format via ReportFormatSchema", () => {
|
|
736
|
+
const result = parseArgs([
|
|
737
|
+
"test-server",
|
|
738
|
+
"--config",
|
|
739
|
+
"config.json",
|
|
740
|
+
"--format",
|
|
741
|
+
"xml",
|
|
742
|
+
]);
|
|
743
|
+
expect(result.helpRequested).toBe(true);
|
|
744
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Invalid format"));
|
|
745
|
+
});
|
|
746
|
+
it("accepts short flag -f for format", () => {
|
|
747
|
+
const result = parseArgs([
|
|
748
|
+
"test-server",
|
|
749
|
+
"--config",
|
|
750
|
+
"config.json",
|
|
751
|
+
"-f",
|
|
752
|
+
"json",
|
|
753
|
+
]);
|
|
754
|
+
expect(result.format).toBe("json");
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
describe("AssessmentProfileNameSchema integration", () => {
|
|
758
|
+
it("parseArgs validates profile name with AssessmentProfileNameSchema", () => {
|
|
759
|
+
const result = parseArgs([
|
|
760
|
+
"test-server",
|
|
761
|
+
"--config",
|
|
762
|
+
"config.json",
|
|
763
|
+
"--profile",
|
|
764
|
+
"security",
|
|
765
|
+
]);
|
|
766
|
+
expect(result.profile).toBe("security");
|
|
767
|
+
});
|
|
768
|
+
it("parseArgs rejects invalid profile via AssessmentProfileNameSchema", () => {
|
|
769
|
+
const result = parseArgs([
|
|
770
|
+
"test-server",
|
|
771
|
+
"--config",
|
|
772
|
+
"config.json",
|
|
773
|
+
"--profile",
|
|
774
|
+
"invalid-profile",
|
|
775
|
+
]);
|
|
776
|
+
expect(result.helpRequested).toBe(true);
|
|
777
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Invalid profile name"));
|
|
778
|
+
});
|
|
779
|
+
it("accepts all valid profiles: quick, security, compliance, full", () => {
|
|
780
|
+
const validProfiles = ["quick", "security", "compliance", "full"];
|
|
781
|
+
for (const profile of validProfiles) {
|
|
782
|
+
consoleErrorSpy.mockClear();
|
|
783
|
+
const result = parseArgs([
|
|
784
|
+
"test-server",
|
|
785
|
+
"--config",
|
|
786
|
+
"config.json",
|
|
787
|
+
"--profile",
|
|
788
|
+
profile,
|
|
789
|
+
]);
|
|
790
|
+
expect(result.profile).toBe(profile);
|
|
791
|
+
expect(result.helpRequested).toBeFalsy();
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
describe("Module names validation via safeParseModuleNames", () => {
|
|
796
|
+
it("parseArgs validates --skip-modules with valid module names", () => {
|
|
797
|
+
const result = parseArgs([
|
|
798
|
+
"test-server",
|
|
799
|
+
"--config",
|
|
800
|
+
"config.json",
|
|
801
|
+
"--skip-modules",
|
|
802
|
+
"temporal,security",
|
|
803
|
+
]);
|
|
804
|
+
expect(result.skipModules).toContain("temporal");
|
|
805
|
+
expect(result.skipModules).toContain("security");
|
|
806
|
+
});
|
|
807
|
+
it("parseArgs validates --only-modules with valid module names", () => {
|
|
808
|
+
const result = parseArgs([
|
|
809
|
+
"test-server",
|
|
810
|
+
"--config",
|
|
811
|
+
"config.json",
|
|
812
|
+
"--only-modules",
|
|
813
|
+
"functionality,errorHandling",
|
|
814
|
+
]);
|
|
815
|
+
expect(result.onlyModules).toContain("functionality");
|
|
816
|
+
expect(result.onlyModules).toContain("errorHandling");
|
|
817
|
+
});
|
|
818
|
+
it("parseArgs rejects invalid module names with helpful error", () => {
|
|
819
|
+
const result = parseArgs([
|
|
820
|
+
"test-server",
|
|
821
|
+
"--config",
|
|
822
|
+
"config.json",
|
|
823
|
+
"--skip-modules",
|
|
824
|
+
"invalid-module",
|
|
825
|
+
]);
|
|
826
|
+
expect(result.helpRequested).toBe(true);
|
|
827
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Invalid module name"));
|
|
828
|
+
});
|
|
829
|
+
it("parseArgs rejects mix of valid and invalid module names", () => {
|
|
830
|
+
const result = parseArgs([
|
|
831
|
+
"test-server",
|
|
832
|
+
"--config",
|
|
833
|
+
"config.json",
|
|
834
|
+
"--only-modules",
|
|
835
|
+
"security,not-a-real-module",
|
|
836
|
+
]);
|
|
837
|
+
expect(result.helpRequested).toBe(true);
|
|
838
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Invalid module name"));
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
});
|