Skip to content

Commit

Permalink
Add dagit test to make sure Permission flags stay in sync (#7117)
Browse files Browse the repository at this point in the history
* add perm test

* generate permissions
  • Loading branch information
prha committed Mar 18, 2022
1 parent 8b3ad9f commit 5efccff
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pylint:
#
# NOTE: Use `extend-exclude` instead of `exclude`. If `exclude` is provided, it stops black from
# reading gitignore. `extend-exclude` is layered on top of gitignore. See:
# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
black:
black --fast \
--extend-exclude="examples/docs_snippets|snapshots" \
Expand Down Expand Up @@ -60,7 +60,7 @@ install_dev_python_modules_verbose:
python scripts/install_dev_python_modules.py

graphql:
cd js_modules/dagit/; make generate-graphql
cd js_modules/dagit/; make generate-graphql; make generate-perms

sanity_check:
#NOTE: fails on nonPOSIX-compliant shells (e.g. CMD, powershell)
Expand Down
3 changes: 3 additions & 0 deletions js_modules/dagit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dev_webapp:
generate-graphql:
yarn workspace @dagster-io/dagit-core generate-graphql

generate-perms:
yarn workspace @dagster-io/dagit-core generate-perms

ts:
yarn workspace @dagster-io/dagit-app ts && yarn workspace @dagster-io/dagit-core ts && yarn workspace @dagster-io/ui ts

Expand Down
1 change: 1 addition & 0 deletions js_modules/dagit/packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"check-prettier": "prettier --list-different \"./src/**/*.tsx\"",
"ts": "tsc -p .",
"generate-graphql": "ts-node -O '{\"module\": \"commonjs\"}' ./src/scripts/generateGraphQLTypes.ts",
"generate-perms": "ts-node -O '{\"module\": \"commonjs\"}' ./src/scripts/generatePermissions.ts",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"analyze": "source-map-explorer 'build/static/js/*.js'"
Expand Down
11 changes: 11 additions & 0 deletions js_modules/dagit/packages/core/src/app/Permissions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import permissions from '../graphql/permissions.json';

import {EXPECTED_PERMISSIONS} from './Permissions';

describe('Permissions', () => {
it('Client permissions match graphql permissions', () => {
permissions.forEach(({permission}: {permission: any}) => {
expect(permission in EXPECTED_PERMISSIONS).toBe(true);
});
});
});
17 changes: 17 additions & 0 deletions js_modules/dagit/packages/core/src/app/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import * as React from 'react';
import {PermissionFragment} from './types/PermissionFragment';
import {PermissionsQuery} from './types/PermissionsQuery';

// used in tests, to ensure against permission renames. Should make sure that the mapping in
// extractPermissions is handled correctly
export const EXPECTED_PERMISSIONS = {
launch_pipeline_execution: true,
launch_pipeline_reexecution: true,
start_schedule: true,
stop_running_schedule: true,
edit_sensor: true,
terminate_pipeline_execution: true,
delete_pipeline_run: true,
reload_repository_location: true,
reload_workspace: true,
wipe_assets: true,
launch_partition_backfill: true,
cancel_partition_backfill: true,
};

export type PermissionsFromJSON = {
launch_pipeline_execution?: boolean;
launch_pipeline_reexecution?: boolean;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions js_modules/dagit/packages/core/src/scripts/generatePermissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {execSync} from 'child_process';
import {writeFileSync} from 'fs';

console.log('Downloading permissions...');

const TARGET_FILE = './src/graphql/permissions.json';

const result = execSync(
`dagster-graphql --ephemeral-instance --empty-workspace -t 'query { permissions { permission } }'`,
{cwd: '../../../../examples/docs_snippets/'},
).toString();

const permissionJson = JSON.parse(result).data.permissions;

console.log('Generating permissions.json...');

writeFileSync(TARGET_FILE, JSON.stringify(permissionJson));

console.log('Done!');
1 change: 1 addition & 0 deletions js_modules/dagit/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ commands =
echo -e "--- \033[0;32m:Running dagit webapp tests\033[0m"
yarn install
yarn workspace @dagster-io/dagit-core generate-graphql
yarn workspace @dagster-io/dagit-core generate-perms
yarn workspace @dagster-io/dagit-app lint
yarn workspace @dagster-io/dagit-app ts
yarn workspace @dagster-io/dagit-core ts
Expand Down

0 comments on commit 5efccff

Please sign in to comment.