Skip to content

Commit b196aa3

Browse files
author
Kyle Lilly
committed
Add unit tests to the CDK application stacks capturing current posture of CDK baseline applied against controls. Move over pre-commit config.
1 parent 64f6491 commit b196aa3

20 files changed

+1415
-10
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ cdk.context.json
2323
.vscode
2424
.venv
2525
.DS_Store
26+
27+
# Coverage Statistic Folders
28+
coverage
29+
30+
# Model Cache Folders
31+
models

.pre-commit-config.yaml

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: verify-config
5+
name: Verify config file
6+
description: Verify config file to check if certain parameters are empty
7+
entry: scripts/verify-config.sh
8+
verbose: true
9+
language: script
10+
files: config.yaml
11+
12+
- repo: https://github.com/PyCQA/bandit
13+
rev: '1.7.5'
14+
hooks:
15+
- id: bandit
16+
args: [--recursive, -c=pyproject.toml]
17+
additional_dependencies: ['bandit[toml]']
18+
19+
- repo: https://github.com/Yelp/detect-secrets
20+
rev: v1.4.0
21+
hooks:
22+
- id: detect-secrets
23+
exclude: (?x)^(
24+
.*.ipynb|config.yaml
25+
)$
26+
27+
- repo: https://github.com/pre-commit/pre-commit-hooks
28+
rev: v4.5.0
29+
hooks:
30+
- id: check-json
31+
- id: check-yaml
32+
- id: check-case-conflict
33+
- id: mixed-line-ending
34+
args: ['--fix=lf']
35+
- id: fix-byte-order-marker
36+
- id: check-merge-conflict
37+
- id: detect-private-key
38+
- id: end-of-file-fixer
39+
- id: trailing-whitespace
40+
41+
- repo: https://github.com/codespell-project/codespell
42+
rev: v2.2.6
43+
hooks:
44+
- id: codespell
45+
entry: codespell
46+
args: ['--skip=*.git*,*cdk.out*,*venv*,*mypy_cache*,*package-lock*,*node_modules*,*dist/*,*poetry.lock*,*coverage*', "-L=xdescribe"]
47+
pass_filenames: false
48+
49+
- repo: https://github.com/pre-commit/mirrors-prettier
50+
rev: 'v3.0.3'
51+
hooks:
52+
- id: prettier
53+
name: prettier-md
54+
files: .*\.(ya?ml|json|md)$
55+
exclude: ^node_modules/|config.yaml|^dist/
56+
57+
- id: prettier
58+
name: prettier-ts
59+
args: [--write, --config, .prettierrc]
60+
files: \.(ts|tsx)$
61+
exclude: ^node_modules/|^dist/
62+
63+
- repo: https://github.com/pycqa/isort
64+
rev: 5.12.0
65+
hooks:
66+
- id: isort
67+
name: isort (python)
68+
69+
- repo: https://github.com/ambv/black
70+
rev: '23.10.1'
71+
hooks:
72+
- id: black
73+
74+
- repo: https://github.com/charliermarsh/ruff-pre-commit
75+
rev: 'v0.1.3'
76+
hooks:
77+
- id: ruff
78+
args: [--exit-non-zero-on-fix]
79+
80+
- repo: https://github.com/pycqa/flake8
81+
rev: '6.1.0'
82+
hooks:
83+
- id: flake8
84+
additional_dependencies:
85+
- flake8-docstrings
86+
- flake8-broken-line
87+
- flake8-bugbear
88+
- flake8-comprehensions
89+
- flake8-debugger
90+
- flake8-string-format
91+
args:
92+
- --docstring-convention=numpy
93+
- --max-line-length=120
94+
- --extend-immutable-calls=Query,fastapi.Depends,fastapi.params.Depends
95+
- --ignore=B008 # Ignore error for function calls in argument defaults
96+
exclude: ^(__init__.py$|.*\/__init__.py$)
97+
98+
99+
- repo: https://github.com/pre-commit/mirrors-mypy
100+
rev: 'v1.6.1'
101+
hooks:
102+
- id: mypy
103+
verbose: true
104+
# mypy currently fails on the gitlab runner and also fails locally due to the mono
105+
# repo nature of LISA and two "api" modules. This command will make it so mypy
106+
# issues are reported but non-blocking
107+
entry: bash -c 'mypy "$@" || true' --
108+
args:
109+
- --config-file=pyproject.toml
110+
- --install-types
111+
- --non-interactive
112+
exclude: ^test
113+
114+
- repo: https://github.com/pre-commit/mirrors-eslint
115+
rev: 'v8.53.0'
116+
hooks:
117+
- id: eslint
118+
files: \.[jt]sx?$
119+
types: [file]
120+
args:
121+
- --max-warnings=10
122+
- --fix
123+
124+
- repo: https://github.com/Lucas-C/pre-commit-hooks
125+
rev: v1.5.5
126+
hooks:
127+
- id: insert-license
128+
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
129+
args:
130+
- --license-filepath
131+
- .precommit-license-header.txt # defaults to: LICENSE.txt
132+
- --comment-style
133+
- /**| |*/ # defaults to: #
134+
135+
- repo: https://github.com/Lucas-C/pre-commit-hooks
136+
rev: v1.5.5
137+
hooks:
138+
- id: insert-license
139+
files: \.py$
140+
args:
141+
- --license-filepath
142+
- .precommit-license-header.txt # defaults to: LICENSE.txt
143+
- --comment-style
144+
- "# " # defaults to: #

.precommit-license-header.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License").
4+
You may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

CHANGELOG.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
- Customers can now configure LISA to use PGVector in addition or in place of OpenSearch for their RAG repository. LISA can connect to an existing RDS Postgres instance or one can be deployed as part of the LISA deployment.
1414
- PGVector is now the "default" configuration in the `config.yaml` file as PGVector is considerably faster to deploy for demo/test purposes
1515
- [V1282894257] Improved support for custom DNS
16-
- Customers can now specify a custom domain name for the LISA API Gateway as well as the LISA Serve REST ALB. If these values are set in the `config.yaml` file the UI will automaticaly use the correct pathing when making service requests without needing any additional code changes.
17-
- [V1282858379] Move advanced chat configuration options between a collapsable "Advanced configuration" sectoin
16+
- Customers can now specify a custom domain name for the LISA API Gateway as well as the LISA Serve REST ALB. If these values are set in the `config.yaml` file the UI will automatically use the correct pathing when making service requests without needing any additional code changes.
17+
- [V1282858379] Move advanced chat configuration options between a collapsible "Advanced configuration" sectoin
1818
- The chat "control panel" has been redesigned to hide the following items chat buffer, model kwargs, prompt template, and the metadata toggle
1919
- [V1282855530] Add support for Enterprise CDK PermissionBoundaryAspect and custom synthesizer
2020
- Added new property to the `config.yaml` to allow customers to optionally specify a configuration for the PermissionBoundaryAspect. If counfigured the aspect will be applied to all stacks
@@ -27,9 +27,9 @@
2727
- Default is now an `m5.large` however customers can use any instance type they wish although they may need to update `schema.ts` if the instance type isn't already listed there
2828

2929
#### Bugs
30-
- [AIML-ADC-7604] Rag context not visibile in metadata until subsequent messages
30+
- [AIML-ADC-7604] Rag context not visible in metadata until subsequent messages
3131
- This has been addressed by adding a dedicated `ragContext` property to the message metadata. The relevant documents including s3 key will now be visible when sending a message with a RAG repository and embedding model selected.
32-
- [V1283663967] Chat messages ocassionaly wrap
32+
- [V1283663967] Chat messages occasionally wrap
3333
- Sometimes the model returns text that gets wrapped in ``<pre><code> </code></pre>``. The default style for this content now has word-wrap and word-break styles applied to prevent the message overflowing.
3434

3535
#### Additional changes

jest.config.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
/**
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
module.exports = {
218
testEnvironment: 'node',
319
roots: ['<rootDir>/test'],
420
testMatch: ['**/*.test.ts'],
521
transform: {
622
'^.+\\.tsx?$': 'ts-jest'
7-
}
23+
},
24+
collectCoverage: true,
825
};

lib/api-base/authorizer.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import * as cdk from 'aws-cdk-lib';
218
import { RequestAuthorizer, IdentitySource } from 'aws-cdk-lib/aws-apigateway';
319
import { ISecurityGroup, IVpc } from 'aws-cdk-lib/aws-ec2';
@@ -25,7 +41,7 @@ interface AuthorizerProps extends BaseProps {
2541
/**
2642
* Lambda Authorizer Construct.
2743
*/
28-
export class Authorizer extends Construct {
44+
export class CustomAuthorizer extends Construct {
2945
/** Authorizer Lambda */
3046
public readonly authorizer: RequestAuthorizer;
3147

lib/core/api_base.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1+
/**
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { Stack, StackProps } from 'aws-cdk-lib';
2-
import { Cors, EndpointType, IAuthorizer, RestApi, StageOptions } from 'aws-cdk-lib/aws-apigateway';
18+
import { Cors, EndpointType, Authorizer, RestApi, StageOptions } from 'aws-cdk-lib/aws-apigateway';
319
import { IVpc } from 'aws-cdk-lib/aws-ec2';
420
import { Construct } from 'constructs';
521

6-
import { Authorizer } from '../api-base/authorizer';
22+
import { CustomAuthorizer } from '../api-base/authorizer';
723
import { BaseProps } from '../schema';
824

925
interface LisaApiBaseStackProps extends BaseProps, StackProps {
1026
vpc: IVpc;
1127
}
1228

1329
export class LisaApiBaseStack extends Stack {
14-
public readonly authorizer: IAuthorizer;
30+
public readonly restApi: RestApi;
31+
public readonly authorizer: Authorizer;
1532
public readonly restApiId: string;
1633
public readonly rootResourceId: string;
1734
public readonly restApiUrl: string;
@@ -41,11 +58,12 @@ export class LisaApiBaseStack extends Stack {
4158
});
4259

4360
// Create the authorizer Lambda for APIGW
44-
const authorizer = new Authorizer(this, 'LisaApiAuthorizer', {
61+
const authorizer = new CustomAuthorizer(this, 'LisaApiAuthorizer', {
4562
config: config,
4663
vpc,
4764
});
4865

66+
this.restApi = restApi;
4967
this.restApiId = restApi.restApiId;
5068
this.rootResourceId = restApi.restApiRootResourceId;
5169
this.authorizer = authorizer.authorizer;

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@aws-sdk/client-iam": "^3.490.0",
1616
"@aws-cdk/aws-lambda-python-alpha": "2.125.0-alpha.0",
1717
"@cdklabs/cdk-enterprise-iac": "^0.0.400",
18+
"@types/jest": "^29.5.12",
1819
"@types/js-yaml": "^4.0.5",
1920
"@types/node": "20.5.3",
2021
"@typescript-eslint/eslint-plugin": "^6.7.0",

test/cdk/constructs/.placeholder

Whitespace-only changes.

0 commit comments

Comments
 (0)